Help Hacking Gruber's Liberal URL Regex

Rachelew

New Member
I've taken the Liberal URL Regex from Daring Fireball, merged it with some of Alan Storm improvements and hacked my way into fixing some bugs like support for IDN chars inside parentheses. This is what I've:\[code\]/(?:[\w-]+:\/\/?|www[.])[^\s()<>]+(?:(?:\([^\s()<>]*\)[^\s()<>]*)+|[^[:punct:]\s]|\/)/\[/code\]However I've encountered a bug that I'm not being able to solve:\[code\]'www.dsd(sd)sdsd.com' // can also be the valid 'www.dsd.com/whatever(whatever)'\[/code\]The above URL is being recognized as \[code\]www.dsd(sd)sdsd.com'\[/code\] (or \[code\]www.dsd.com/whatever(whatever)'\[/code\]) instead of \[code\]www.dsd(sd)sdsd.com\[/code\] (or \[code\]www.dsd.com/whatever(whatever)\[/code\]). This only seems to happen when the URL has parentheses, since the following URL:\[code\]'www.sampleurl.com'\[/code\]Is correctly being recognized as \[code\]www.sampleurl.com\[/code\].I think the \[code\][^[:punct:]\s]|\/\[/code\] part of the regex is not being executed when the URL has parentheses, I've been trying for some time but I can't seem to find a solution. Can anyone help me?For commodity, I've set up a Rubular permalink with the regex and some test data (the last URL fails).I think that Gruber's regex was a little rushed, for instance it doesn't match URL's like:\[code\]http://en.wikipedia.org/wiki/Something_(Special)_For_You\[/code\]I'm even more impressed by seeing that both Gruber and Alan missed this really simple typo:\[code\]\([\w\d]+\)\[/code\]Wouldn't \[code\]\(\w+\)\[/code\] be enough? :S
 
Back
Top