Say I have some text like so:
Lorem Ipsum <a href="http://www.youtube.com/watch?v=E6USO8krrmU">http://www.youtube.com/watch?v=E6USO8krrmU</a> blah blah blah <a href="http://www.google.com" target="_blank">Google</a> it's hot outside <a href="http://www.youtube.com/watch?v=E6USO8krrmU" class="class1 class2">http://www.youtube.com/watch?v=E6USO8krrmU</a>
..and I want to remove the link from around it if the href attribute contains youtube - for the sake of this example.
The output should be:
Lorem Ipsum http://www.youtube.com/watch?v=E6USO8krrmU blah blah blah <a href="http://www.google.com" target="_blank">Google</a> it's hot outside http://www.youtube.com/watch?v=E6USO8krrmU
How can I achieve this?
While I have your attention, if anyone has any links to a good place to start learning regex I'd love to hear it.
$('a').filter(function() {
return $(this).attr('href').lastIndexOf('youtube') >= 0;
}).contents().unwrap();
I got there in the end with:
$string = preg_replace('#<a href="https?://www.youtube.*?>([^>]*)</a>#i', '$1', $string);