title: RegEx, look for URL's where it does not start with ="
body: <p>I am trying to build a function to find URL's in strings and change them into links. But I do not want to find URL's that is already inside a HTML tag (Like <code>&lt;A&gt;</code> and <code>&lt;IMG&gt;</code> as examples).</p>
  
  <p>In other words the RegEx should find this and replace it with a link:</p>
  
  <pre><code>http://www.stackoverflow.com
  www.stackoverflow.com
  www.stackoverflow.com/logo.gif
  </code></pre>
  
  <p>But not these URL's (Since they are already formated):</p>
  
  <pre><code>&lt;a href="http://www.stackoverflow.com"&gt;http://www.stackoverflow.com&lt;/a&gt;
  &lt;img src="http://www.stackoverflow.com/logo.gif"&gt;
  </code></pre>
  
  <p>I am using a RegEx that is already developed for this, but it does not check if the URL is inside a HTML-element already. (<a href="http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without" rel="nofollow">http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without</a>)</p>
  
  <p>This is the original RegEx:</p>
  
  <pre><code>/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&amp;=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&amp;=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&amp;;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/
  </code></pre>
  
  <p>This the same RegEx with explanations:</p>
  
  <pre><code>(
    ( // brackets covering match for protocol (optional) and domain
      ([A-Za-z]{3,9}:(?:\/\/)?) // match protocol, allow in format http:// or mailto:
      (?:[\-;:&amp;=\+\$,\w]+@)? // allow something@ for email addresses
      [A-Za-z0-9\.\-]+ // anything looking at all like a domain, non-unicode domains
      | // or instead of above
      (?:www\.|[\-;:&amp;=\+\$,\w]+@) // starting with something@ or www.
      [A-Za-z0-9\.\-]+   // anything looking at all like a domain
    )
    ( // brackets covering match for path, query string and anchor
      (?:\/[\+~%\/\.\w\-]*) // allow optional /path
      ?\??(?:[\-\+=&amp;;%@\.\w]*) // allow optional query string starting with ? 
      #?(?:[\.\!\/\\\w]*) // allow optional anchor #anchor
    )? // make URL suffix optional
  )
  </code></pre>
  
  <p>What I am trying to do is to change this to look for if the URL starts with exactly <code>="</code> or <code>&gt;</code> and if it does, it should not go through the RegEx. Since the URL inside <code>&lt;A&gt;</code> and <code>&lt;IMG&gt;</code> elements should have one of these combinations right before it starts.</p>
  
  <p>I am not the greatest in RegEx but I have tried and I guess this is my best try so far, but it does not do the trick:</p>
  
  <pre><code>/(((^[^\="|\&gt;])([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&amp;=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&amp;=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&amp;;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
  </code></pre>
  
  <p>It is this part I have added:</p>
  
  <pre><code>(^[^\="|\&gt;])
  </code></pre>
  
  <p>This is my fiddle:</p>
  
  <p><a href="http://jsfiddle.net/0w1g4mm9/2/" rel="nofollow">http://jsfiddle.net/0w1g4mm9/2/</a></p>