title: How do I fix "invalid group" error when attempting to use Gruber's "improved" URL matching regexp pattern in JavaScript?
body: <p>I'm attempting to integrate John Gruber's <a href="http://daringfireball.net/2010/07/improved_regex_for_matching_urls" rel="noreferrer">An Improved Liberal, Accurate Regex Pattern for Matching URLs</a> into one of my Javascripts, but WebKit's inspector (in Google Chrome 5.0.375.125 for Mac) gives an "Invalid group" regular expression syntax error.</p>
  
  <p>Gruber's original regexp is as follows:</p>
  
  <pre><code>(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:'".,&lt;&gt;?«»“”‘’]))
  </code></pre>
  
  <p>The line from my JavaScript w/the regexp is as follows (w/forward slashes backslash-escaped):</p>
  
  <pre><code>tweet_text = tweet_text.replace(/(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:'".,&lt;&gt;?«»“”‘’]))/gi, '&lt;a href="$1"&gt;$1&lt;/a&gt;');
  </code></pre>
  
  <p>And the Google Chrome (V8?) error is as follows:</p>
  
  <pre><code>Uncaught SyntaxError: Invalid regular expression: /(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:'".,&lt;&gt;?«»“”‘’]))/: Invalid group
  </code></pre>
  
  <p>And the Safari error is as follows:</p>
  
  <pre><code>SyntaxError: Invalid regular expression: unrecognized character after (?
  </code></pre>
  
  <p>He claims it should work in modern JavaScript regexp interpreters, which I'd assume WebKit &amp; V8 would be. Does JavaScript's regexp syntax not support the <code>(?:</code> (damn Google for not indexing punctuation!) grouping syntax? Did I just miss escaping something? </p>