PHP - preg_match_all to find all URLs

I am trying to figure out a regular expression that matches all URLs and the text the link is on.

I have found expressions that return the URL, but Im stumped at getting the actual text of the URL aswell.

Any help would be greatly appreciated.

OK, this is getting close,

preg_match_all("/<a.*?href=[\\"']?(.*?)[\\"']?.*?>(.*?)<\\/a>/i", $str, $matches); 

$matches[0] contains the full <a> tag including the text and closing tags.
$matches[1] is empty :frowning: what am I missing here… it should be the URL…
$matches[2] is the text of the link (or the image) (Perfect!)

Well if any one else ever needs the answer for this one, here ya go!!

preg_match_all("'<a.*?href=\\"(http[s]*://[^>\\"]*?)\\"[^>]*?>(.*?)</a>'si", $str, $matches);