Forum Moderators: coopster
this is <a href="link1.htm">link1</a> and this is <a href="link2.html">link2</a>
The regex that Claus gave will match
="link1.htm">link1</a> and this is <a href="link2.html">link2<
To match a single link, you need to make it ungreedy, as in
$pattern = '/<a\s[^>]*href=["\']?(.+)[\'"\s>]/U';
In English: find a tag that starts with '<a' followed by white space and zero or more other characters that do not close the tag, stopping at the first "href=" encountered, followed or not by single or double quotes, then after that grab anything you find up until you encounter either a close quote or a space or a close tag.
So in
this is <a href="link1.htm">link1</a> and this is <a href="link2.html">link2</a>
This will match
link1.htm
If you want all them, plug that pattern into preg_match_all. If you want the whole thing (from <a> to </a>) you will need to enclose it all in parens for the capture.