News for hackers. Stuff that matters.
Re:A Liberal, Accurate Regex Pattern for Matching URLs by ehsanul on Friday November 27, 2009 @03:08PM (#964317)
I was using a monster of a regex for validating URLs in a Ruby (Sinatra) app, and it wasn't even looking in unstructured text). Found it at http://snipplr.com/view/6889/regular-expressions-for-uri-val...

/^(https?):\/\/((?:[a-z0-9.\-]|%[0-9A-F]{2}){3,})(?::(\d+))?((?:\/(?:[a-z0-9\-._~!$&'()+,;=:@]|%[0-9A-F]{2})))(?:\?((?:[a-z0-9\-._~!$&'()+,;=:\/?@]|%[0-9A-F]{2})))?(?:#((?:[a-z0-9\-._~!$&'()+,;=:\/?@]|%[0-9A-F]{2})*))?$/i

Yeah, more involved. Though it parses it into the url parts, and it does work.

Re:A Liberal, Accurate Regex Pattern for Matching URLs by wingo on Friday November 27, 2009 @03:58PM (#964364)
It looks like line noise. But it's funny though, I can read regexps better than I can read formal semantics. Having tried once this evening to read http://matt.might.net/papers/might2007diss.pdf, regexps are refreshing :)
Re:A Liberal, Accurate Regex Pattern for Matching URLs by mahmud on Friday November 27, 2009 @08:57PM (#964687)
Please do not link to random papers on semantics, you don't know whose weekend you might ruin.

Horrible nerd-snipping there; I grok half of the paper, and have no choice but to study the formal semantics of the other half :-(

Re:A Liberal, Accurate Regex Pattern for Matching URLs by PStamatiou on Saturday November 28, 2009 @02:08AM (#964899)
Matt Might (author of linked PDF) was my Computer Science TA four or five years ago at Georgia Tech... for a java class. small world haha
Re:A Liberal, Accurate Regex Pattern for Matching URLs by riffraff on Friday November 27, 2009 @05:30PM (#964457)
what is wrong with URI.parse in the stdlib? the articles' re goes out of url validation to get urlish things in free text, (e.g. " lokk at http://goo.com/bat, lovely" the comma would actually be part of a valid url, but the regex tries to detect this. Yet, for url validation ruby's lib is enough, I believe.
Re:A Liberal, Accurate Regex Pattern for Matching URLs by ehsanul on Friday November 27, 2009 @09:07PM (#964698)
Well, with URI.parse, you can send in a ftp uri, or just "something.com" (which is parsed as just a path). So not really what I need from URL validation. If there's something else I'm missing, I'm happy to know.

Edit: And btw, for an industrial-strength Ruby URI library (to replace the standard library), check out Addressable: http://addressable.rubyforge.org/

Re:A Liberal, Accurate Regex Pattern for Matching URLs by riffraff on Saturday November 28, 2009 @04:14AM (#964978)
try URI.regexp('http') :)