Help with an html link regex <a href>
Posted: Tue Sep 04, 2007 12:34 pm
Hi all
First off here's the current regex
Bascially it's used in the PHP preg_match_all function to find all the links in a piece of html and do something with them. Up until now it has worked perfectly.
However, today a new test was suggested (one stupidly overlooked) and it failed miserably. I was hoping you guys could help suggest a fix.
If
or variants is used everything is fine, but (and a it's big but)
if
is used, basically having any tags inside the anchor tag, then the whole thing is skipped by the regex.
I have a basic grasp of regex, but to be honest I don't think this is one of mine. I'm now the only dev on the project so looking forward to suggestions and many thanks in advance to any one who can help.
First off here's the current regex
Code: Select all
$linkPattern = '/<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/mi';However, today a new test was suggested (one stupidly overlooked) and it failed miserably. I was hoping you guys could help suggest a fix.
If
Code: Select all
<a href="http://your/link/here">Click</a>if
Code: Select all
<a href="http://your/link/here">
<any other html tag>
Click
</close any tag>
</a>I have a basic grasp of regex, but to be honest I don't think this is one of mine. I'm now the only dev on the project so looking forward to suggestions and many thanks in advance to any one who can help.