Regex ignore URL already in HTML tags

混江龙づ霸主 提交于 2019-11-27 16:15:00

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!