Last active
September 1, 2015 14:20
-
-
Save triskweline/dd76aee4713cd5b8d66e to your computer and use it in GitHub Desktop.
Regular expression to sanity check URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL = %r{ | |
\A # Beginning of string | |
(http|https) # $1: Scheme | |
:\/\/ # :// | |
([\w\-_]+(?:\.[\w\-_]+)*) # $2: Hostname. Does not begin or end with a dot. No two dots in a row. | |
(?::(\d+)) # $3: Port (without leading colon) | |
(/[^/\?\#]*) # $4: Path (with leading slash) | |
(?:\?([^\#]*)) # $4: Query (without leading question mark) | |
(?:\#(.*)) # $5: Hash (without leading hash) | |
\z # End of string | |
}x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment