Web
Match a domain name
Flags: gi
Match domain names like example.com or sub.example.co.uk.
Pattern
Regular expression
(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}How it works
Each label is 1–63 chars, starts and ends with alphanumeric, may contain hyphens. TLD is 2–63 alpha characters. This is a practical subset of RFC 1035 syntax that covers real-world domains.
Matches
- ▸example.com
- ▸sub.example.co.uk
- ▸a.io
Non-matches
- ▸-invalid.com (leading hyphen)
- ▸example (no TLD)
Common gotchas
This matches domain-only strings, not full URLs. Prepending `https?://` gives you the URL matcher. Also, this does not validate that the TLD actually exists — use the IANA TLD list for that.
Language snippets
JavaScript
const re = /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}/gi;Python
re.findall(r"(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}", text, re.I)Go
re := regexp.MustCompile(`(?i)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}`)Java
Pattern.compile("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}", Pattern.CASE_INSENSITIVE)