I have a block of code that will take a block of text like the following:
Sample text sample text http://www.google.com sample text
Add code to the beginning of the pattern to capture an opening anchor tag, and then do not perform the callback code when it has captured something:
/(<a[^>]*>)?http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)/
You will then need to add an if to your lamda function to see if there is anything in $matches[1] (Don't forget to increment your captures as well)
You cannot use a negative look behind assertion here as the capture is not a fixed length, but you could use a negative look ahead assertion for the closing tag so it drops the entire match:
/(<a[^>]*>)?http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)(?!<\/a>)/