0

I want to match any URL that isn't already enclosed in an href. i.e I want to ignore the following.

<a href="http://www.test.com/whatever">

I'm trying to write a regex to automatically find urls, so that I can turn them into marked up a hrefs.

The issue I'm having is dealing with urls that have already been marked up (The documents contain a mix of marked up and not marked up urls).

bobble bubble
  • 11,625
  • 2
  • 24
  • 38
Tom
  • 1
  • Another duplicate...: [regex-to-turn-urls-into-links-without-messing-with-existing-links-in-the-text](http://stackoverflow.com/questions/980902/regex-to-turn-urls-into-links-without-messing-with-existing-links-in-the-text) – Tim Pietzcker Oct 23 '09 at 09:57

1 Answers1

0

Use negative look ahead to see if an url does NOT have </a> ahead of it

your_regex(?!\s*</a>)
Zombo
  • 1
  • 55
  • 342
  • 375
Bart Kiers
  • 161,100
  • 35
  • 287
  • 281