开发者

Do not match if within tag

I have this regex which detects url formatted text:

/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/

so it would detect something like http://google.com

My problem is that I do not want it to detect the links when the links are inside tags such as <开发者_运维技巧;a href="http://google.com">http://www.google.com</a> - so in there it should not detect anything. Help?

EDIT - I do NOT want to match the anchor tag. The above regex matches links inside anchor tags which is what I do not want. I need it to match links only outside of tags.


this one should work

/(?!href.*?=.*?['"]+)(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/


/(?<!href=['"])(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜