Skip to content

Instantly share code, notes, and snippets.

@reisdev
Last active October 1, 2019 19:20
Show Gist options
  • Save reisdev/d1ce65c7a676aa5b42fda481316fd80f to your computer and use it in GitHub Desktop.
Save reisdev/d1ce65c7a676aa5b42fda481316fd80f to your computer and use it in GitHub Desktop.
Regular Expression to match URL's

Regular Expression to match URL's

http(s)?:\/\/([a-z-A-Z-0-9]+(\.))+([a-z-A-Z]+)(\/[a-z-A-Z-0-9]*)*(\?((\&)?(.)+=(.)+)*)?

The regex above can be tested here

Step by Step

http(s)?:\/\/

Matches the http:// or https://

([a-z-A-Z-0-9]+(\.))+

Matches the domain and subdomain

([a-z-A-Z]+)

Matches a .com, .net, .io, etc.

(\/[a-z-A-Z-0-9]*)*

Matches the routes, like /post/1, /news, etc.

(\?((\&)?(.)+=(.)+)*)?

Match the url parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment