Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?<protocol>\w*)\:\/\/(?<username>[\w\-]*@)?(?<domain>(?:(?<thld>[\w\-]*)\.)?(?<sld>[\w\-]*)\.(?<tld>[a-zA-Z]*))(?:\:(?<port>\d*))?
/
gm

Description

Get Complete Domain with protocol, username, Third-Level-Domain, Second-Level-Domain, Top-Level-Domain and Port

For Example:

Course at https://udemy.com/path/to/course Test at http://user@sample.com/path Something ftp://domain.com:80/any

Group names:

protocol: Protocol username: Username domain: Complete Domain thld: Third-Level-Domain sld: Second-Level-Domain tld: Top-Level-Domain port: Port

Submitted by amnd33p - 5 months ago (Last modified 5 months ago)