0

I there any JavaScript way (regex) or module to check if a string is a URL which the follows following schema http://en.wikipedia.org/wiki/URI_scheme.

NOTE - I have seen other questions related to this in stackoverflow and none of them are satisfactory. Most of them are the regex which matches the http/https/ftp URL but what about feed or mailto URL or URL with any other schema as specified in http://en.wikipedia.org/wiki/URI_scheme

r.bhardwaj
  • 1,603
  • 6
  • 28
  • 54

1 Answers1

0

The following regex does what you are requesting.

It validates a string if it holds a URL as specified in RFC 3986.

Both absolute and relative URLs are supported.

^([a-z][a-z0-9+\-.]*:(//([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/?|(/?[a-z0-9\-._~%!$&'()*+,;=:@]+(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/?)?)| ([a-z0-9\-._~%!$&'()*+,;=@]+(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/?|(/[a-z0-9\-._~%!$&'()*+,;=:@]+)+/?))(\?[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?(\#[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?$

I did not come up with this regex, it is created by JGSoft

Vasili Syrakis
  • 9,321
  • 1
  • 39
  • 56