Forum: Ruby on Rails HTTP validation regexp, possible solution

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-06-14 00:11
(Received via mailing list)
There was an old email thread from the end of January 2006 discussing
regular expressions for matching URLs. I took some of the sample
expressions and tweaked them a bit to the point where I think they
are pretty useful. They pass all of my tests anyway. :-)

For a reminder, here's a sample message from that thread. My code is
below it.

On Jan 26, 2006, at 5:28 AM, Nathaniel S. H. Brown wrote:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Subject: Re: [Rails] [ANN] HTTP URL validation plugin
>> Sorry, my REGEX skills are quite poor..
>> Jeroen

Nathaniel's expression almost worked. It didn't match properly on
URLs that contained a port designation and it failed to match if a
URL didn't have '.com' or similar on the end of the host (like http://
localhost). Here's an expression that's working pretty well for me.
Thanks to Nathaniel's work, and others, it didn't take me as much
effort as I feared.


I hope this is useful to somebody. If you make any further
improvements, please post them back to the list!

This topic is locked and can not be replied to.