Skip to main content
Regexflux

Domain Name

intermediate

Matches valid domain names like example.com or sub.domain.co.uk.

domaindnshostnameweb

Pattern

/(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}/g

Try It

0 of 6 strings matched

Explanation

Matches one or more DNS labels (alphanumeric with hyphens, max 63 chars each, not starting or ending with a hyphen) separated by dots, ending with a TLD of 2+ letters.

Test Strings

Matching

  • example.com
  • sub.domain.co.uk
  • my-site.org

Non-matching

  • localhost
  • 123.456
  • just-a-word

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns