Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^((http|https|ftp|ftps):\/\/)?(?<url_host>(\[[^\]]+\]|[^\/:\n]+))(?<url_port>(:\d+)?)(\/)?
/
gm

Description

Pulling host domain from URL that can be in any format (protocol listed or not, path listed or not, IPv4 or 6 addresses, port)

Submitted by Drew G - 7 years ago