Skip to content

Instantly share code, notes, and snippets.

@ewliang
Last active October 19, 2018 18:13
Show Gist options
  • Save ewliang/43b4f0dcda784d64813ddf4353fd5a46 to your computer and use it in GitHub Desktop.
Save ewliang/43b4f0dcda784d64813ddf4353fd5a46 to your computer and use it in GitHub Desktop.
A list of RegEx expressions I made which are tested and works.
Created by Eric Liang
https://www.eric-liang.com
Root Domain Matcher
/(https:\/\/|http:\/\/)?((www.)?([a-z\-]+.))?(([a-z\-]+)(?:\.\w+)+)/i
- Supports with or without http, https, or www. in the front of a domain name.
- Supports long segmented subdomains.
- Supports long suffix domain extensions (e.g. .co.uk).
- Supports any domain roots (e.g. .com, .net, .io, .club, etc.)
One disclaimer is it doesn't check whether or not the domain suffix is a valid one, so that's up to you! For instance, if the user tries to make something like www.mywebsite.myawesomewebsite/ and if .myawesomewebsite is not a valid TLD, then it will fail. This part is up to you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment