Hey, Does anybody have a regexp for validating URLs? I found this one and am trying to adapt it: ^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\''\\\+&%\$#\=~_\-]+))*$ (http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21245168.html) I also found this one, but, um, well... http://www.foad.org/~abigail/Perl/url3.regex http://www.foad.org/~abigail/Perl/url2.html Thanks, Joe -- Posted via http://www.ruby-forum.com/.
Joe wrote:> Hey, > > Does anybody have a regexp for validating URLs? I found this one and am > trying to adapt it: > > ^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\''\\\+&%\$#\=~_\-]+))*$ > > (http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21245168.html)It depends what rules you''re trying to validate against. The simplest thing to do is probably to use the regex from RFC 2396: (([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*)) and then split out the component parts and validate them separately. That way you can check that the server name has a reasonable tld, and that the scheme matches something valid, and so on. Check the rfc for details.> > I also found this one, but, um, well... > http://www.foad.org/~abigail/Perl/url3.regexIck! Mind-bleach, quick! -- Alex
On 2/21/06, Joe <joe@yahoo.com> wrote:> Hey, > > Does anybody have a regexp for validating URLs? I found this one and am > trying to adapt it: > > ^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\''\\\+&%\$#\=~_\-]+))*$ > > (http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21245168.html) > > I also found this one, but, um, well... > http://www.foad.org/~abigail/Perl/url3.regex > http://www.foad.org/~abigail/Perl/url2.html > > Thanks, > Joe > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Hello, You remembered me that I wanted to have a RFC-compliant URI regexp Well, this is done now, I''ve just translated the RFC into some ruby code to make a regexp string See the attachement. -------------- next part -------------- A non-text attachment was scrubbed... Name: uri.rb Type: application/octet-stream Size: 2030 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060225/d5168b08/uri-0001.obj