Regular Expressions 101

Community Patterns

Basic sanity syntax check of International Domain Names (converted to ASCII)

0

Regular Expression
PCRE (PHP <7.3)

/
^ (?(DEFINE)(?<part>(?:xn--)?[a-z\d](?:[a-z\d-]*[a-z\d])?)) (?(DEFINE)(?<subpart>(?:xn--)?[a-z\d_](?:[a-z\d_-]*[a-z\d])?)) (?:(?&subpart)\.)* (?&part) (?:\.[a-z]+|\.xn--[a-z\d]+){1,2} $
/
xigm

Description

This regex provides a basic syntax sanity check on an International Domain Name (IDN) which has been converted to ASCII (e.g. via the PHP function idn_to_ascii() from the php-intl package.

Does not guarantee the actual domain name is valid (let alone registered), but only a very basic syntax check.

Submitted by Doqnach - 7 years ago