Regular Expressions 101

Community Patterns

Community Library Entry

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