0

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.

user969622
  • 471
  • 2
  • 5
  • 14
  • http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – knittl Sep 28 '11 at 17:38

2 Answers2

0

this one should work

/(?!href.*?=.*?['"]+)(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/
genesis
  • 50,477
  • 20
  • 96
  • 125
0
/(?<!href=['"])(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/
animuson
  • 53,861
  • 28
  • 137
  • 147
Paul
  • 139,544
  • 27
  • 275
  • 264
  • Hmm after some usage it stopped functioning in some cases such as ` http://www.test.com/` If two alike links are present it matches both of them. How can this be fixed? – user969622 Sep 29 '11 at 00:46