Tehre doesn't appear to be a clear answer on how to do this the best way.
I have some bbcode which may have links in bbcode format:
[url=http://thisisalink.com]link[/url]
as well as possible copy/pasted urls:
I want to replace both instances with a clickable link. I currently have the following: regexs running:
"/\[link=http:\/\/(.*?)\](.*?)\[\/link\]/is"
"/\[link=https:\/\/(.*?)\](.*?)\[\/link\]/is"
"/\[link=(.*?)\](.*?)\[\/link\]/is"
$URLRegex = '/(?:(?<!(\[\/link\]|\[\/link=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '\S+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![[:punct:]])(\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
It just seems that I can't get both to work. In this case, the last regex seems to unlink the first regex.
Surely this has been documented somewhere on the best way to get both bbcode links and pasted URLs to link up together without conflicting with each other.