I am trying to integrate John Gruber's Improved Liberal, Accurate Regular Expression Pattern for matching URLs in one of my Javascripts, but the WebKit inspector (on Google Chrome 5.0.375.125 for Mac) gives the regular expression syntax error "Invalid group".
The original Gruber regex is as follows:
(?i)\b((?:[az][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][az]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?ยซยป""'']))
A line from my regex JavaScript is as follows: (w / forward slashes backslash-escaped):
tweet_text = tweet_text.replace(/(?i)\b((?:[az][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][az]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?ยซยป""'']))/gi, '<a href="$1">$1</a>');
And the Google Chrome bug (V8?) Looks like this:
Uncaught SyntaxError: Invalid regular expression: /(?i)\b((?:[az][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][az]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?ยซยป""'']))/: Invalid group
And the Safari error looks like this:
SyntaxError: Invalid regular expression: unrecognized character after (?
He claims that he should work in modern regexp JavaScript interpreters, which I would suggest that WebKit and V8 will. JavaScript syntax regexp does not support grouping syntax (?: (Damn google for not indexing punctuation!)? I just missed something?
javascript regex
morgant
source share