Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
`
^(?:[_a-z0-9](?:[_a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?)?$
`
igm
Input 1
1
New
This regexp can be used to validate domain names in Golang. While it cannot enforce the 253 character limit (with optional trailing period not included) that can be easily done by a simple len(domain) <= 253 check as well. This can be used as-is in other languages, even with RE2 regex engine. If positive lookbehind assertions are available, the character limit can be used. Non-capturing groups are used. Example validated domains (some may be invalid per TLD rules): example.com _25._tcp.SRV.example punycoded-idna.xn--zckzah under_score.example Example invalid domains: 192.0.2.1 has spaces.com easy,typo.example domain\.escapes.invalid no_trailing_.invalid -leading-or-trailing-.hyphens.invalid TLDs have more validation, the following will not validate: example digit.1example underscore._example_com but with a trailing period, the same rules as non-TLD are applied: example. 192.0.2.1. digit.1example. underscore._example_com.
Substitution
This regexp can be used to validate domain names in Golang. While it cannot enforce the 253 character limit (with optional trailing period not included) that can be easily done by a simple len(domain) <= 253 check as well. This can be used as-is in other languages, even with RE2 regex engine. If positive lookbehind assertions are available, the character limit can be used. Non-capturing groups are used. Example validated domains (some may be invalid per TLD rules): example.com _25._tcp.SRV.example punycoded-idna.xn--zckzah under_score.example Example invalid domains: 192.0.2.1 has spaces.com easy,typo.example domain\.escapes.invalid no_trailing_.invalid -leading-or-trailing-.hyphens.invalid TLDs have more validation, the following will not validate: example digit.1example underscore._example_com but with a trailing period, the same rules as non-TLD are applied: example. 192.0.2.1. digit.1example. underscore._example_com.