Domain Name
intermediateMatches 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,}/gTry 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
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full 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);