Regular Expressions 101

Community Patterns

Domain

1

Regular Expression
PCRE (PHP <7.3)

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

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 - 8 years ago