Skip to content

Instantly share code, notes, and snippets.

@wiltonbsilva
Last active August 13, 2018 17:55
Show Gist options
  • Save wiltonbsilva/637220888326cbb9980e to your computer and use it in GitHub Desktop.
Save wiltonbsilva/637220888326cbb9980e to your computer and use it in GitHub Desktop.
Regular Expression to match simple domain names
RegEx:
^(\.?[a-z0-9]{3,9}(\.?[a-z]{2,3})*)$
Test:
www.google.com
Test:
www.google.com.br
Test:
radio.uol.com.br
Test:
www.ec0.com.br
@adriaandotcom
Copy link

Hm, this is a little too simple, even for human errors:

'twowords'.match(/^(\.?[a-z0-9]{3,9}(\.?[a-z]{2,3})*)$/)[0] // twowords

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