Regular Expressions 101

Community Patterns

Domain name only

0

Regular Expression
PCRE (PHP <7.3)

/
(?:(?:(?<thld>[\w\-]*)(?:\.))?(?<sld>[\w\-]*))\.(?<tld>\w*)
/

Description

Domain with protocol, Third-Level-Domain, Second-Level-Domain, Top-Level-Domain and Port.

as an an example: http://www.example.de https://chat.example.com:80

Group names: 'protocol': Protocol 'thld': Third-Level-Domain 'sld': Second-Level-Domain 'tld': Top-Level-Domain 'port': Port

Submitted by NiRu - 5 years ago