Skip to content

Instantly share code, notes, and snippets.

@Nondv
Created September 7, 2016 14:35
Show Gist options
  • Save Nondv/1cca13642463711a1e8e13c4e6a47c7c to your computer and use it in GitHub Desktop.
Save Nondv/1cca13642463711a1e8e13c4e6a47c7c to your computer and use it in GitHub Desktop.
My regexp for URL
proto = '(https?://)'
domain = '([\w\-\.]+\w)'
path = '((/[\w\-]*)+)'
format = '(\.\w*)'
params = '(\?[^\n]*)' # whatever except \n
re = Regexp.new("\\A#{proto}#{domain}(#{path}#{format}?)?#{params}?\\z")
# ==> /\A(https?:\/\/)([\w\-\.]+\w)(((\/[\w\-]*)+)(\.\w*)?)?(\?[^\n]*)?\z/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment