URL Regular Expression
2
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.
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





I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?