URL Regular Expression





2
Date Submitted Thu. Feb. 28th, 2008 4:10 PM
Revision 1 of 1
Helper inxilpro
Tags "Regular | Expression" | regex | RegExp
Comments 1 comments
This is as close to a perfect URL regular expression as I've come. It's based on RFC 3986.

A few caveats:

It only accepts http/https/ftp URLs by design, but you could change that to accept any valid URI pretty easily.

It doesn't support IP-based URLs or authenticated URLs. This is also by design, but you could change that with a little work.
#((ht|f)tp(s?)://)(([a-z0-9]([a-z0-9]|-)*[a-z0-9]|[a-z0-9])\.)+([a-z]([a-z0-9]|-)*[a-z0-9]|[a-z])(/([a-z0-9\.!$&'\(\)*+,;=_~:@-]|%[a-f0-9]{2})*)*(\?[a-z0-9\.!$&'\(\)*+,;=_~:@/?-]*)?(\#[a-z0-9\.!$&'\(\)*+,;=_~:@/?-]*)?#i

Chris M

Comments

Comments Simply luvverly
Wed. Apr. 2nd, 2008 3:05 PM    Scripter sehrgut

Voting

Votes Up


Helper inxilpro
Scripter sehrgut

Votes Down