Regex for domain name
/\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}\b/gi
Matches
Examples
Note
Each label is 1–63 characters and cannot start or end with a hyphen. Internationalised names need converting to punycode first.
Matches in the example
"example.com""sub.example.co.uk""my-site.dev"
Token by token
\ba word boundary(?:a group, not capturing[a-z0-9]one of: “a” to “z” or “0” to “9”(?:a group, not capturing[a-z0-9-]{0,61}one of: “a” to “z”, “0” to “9” or “-”, between 0 and 61 times, as many as possible[a-z0-9]one of: “a” to “z” or “0” to “9”)?end of group, whole group optionally\.the character “.”)+end of group, whole group one or more times, as many as possible[a-z]{2,63}one of: “a” to “z”, between 2 and 63 times, as many as possible\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma