Simply Domain Regexp

Simply Domain Regexp
I need 2 valid and simple regular expressions to use with preg_match, preg_grep and preg_replace php functions.

First expression will be able to check if a string is a valid domain name. I don’t mind if the TLD actually exists. Regexp will match valid fourth, third, and second level domain names from any existing or future extension: any-thing.whatever, mi-subdomain.sub.us.com, mykeywords.co.uk, ídn-domiñios.org.es. It will check as valid both normal and IDN domain names (with direct IDN characters or punny code characters).

Second expression will be able to check if a valid domain name is IDN matching both including IDN characters or punny code ones.

Leave a Reply

Your email address will not be published. Required fields are marked *