Skip to content

Instantly share code, notes, and snippets.

@macasek
Created February 24, 2010 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macasek/313857 to your computer and use it in GitHub Desktop.
Save macasek/313857 to your computer and use it in GitHub Desktop.
IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
URL_REGEX = %r{
(^$)|
(\A
https?:// # http:// or https://
([^\s:@]+:[^\s:@]*@)? # optional username:pw@
( (xn--)?[^\W_]+([-.][^\W_]+)*\.[a-z]{2,6}\.? | # domain (including Punycode/IDN)...
#{IPv4_PART}(\.#{IPv4_PART}){3} ) # or IPv4
(:\d{1,5})? # optional port
([/?]\S*)? # optional /whatever or ?whatever
\Z)
}iux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment