Regular Expressions 101

Community Patterns

1...34567...482

Extract root domain from URL

0

Regular Expression
PCRE (PHP <7.3)

/
(?:[^:]+:\/\/)(?:www\.)*([.a-z0-9]+)+
/

Description

It will extract the root domain from any URL. This includes removing subdomains, www. and the slug.

Submitted by randywolf244 - 2 years ago