Regular Expressions 101

Community Patterns

Domain Regular Expression

1

Regular Expression
PCRE2 (PHP >=7.3)

/
\b(?:https?:\/\/)?(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:\.[a-z]{2,})?\/?
/
gm

Description

Domains with alphanumeric characters ranging from 3 to 9 in length, followed by a top-level domain (TLD) that is 2 to 3 characters long. Also, it accounts for the possibility of second-level domains such as .co.uk.

Submitted by anonymous - 3 months ago (Last modified 3 months ago)