I\'m having a little problem with my Regex
I\'ve made a custom BBcode for my website, however I also want URLs to be parsed too.
I\'m using preg_replace and
Try this
(?<!href=")(\b[\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])
See it here on Regexr
To make it more general you can simplify your lookbehind to check only for "=""
(?<!=")(\b[\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])
See it on Regexr
(?<!href=")
is a negative lookbehind assertion, it ensures that there is no "href="" before your pattern.
\b
is a word boundary that anchors the start of your link to a change from a non word to a word character. without this the lookbehind would be useless and it would match from the "ttp://..." on.