Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(([A-Za-z]{3,9}:(\/\/))([-;:&=\+\$,\w]+)[.]([-;:&=\+\$,\w]+)[.]([-;:&=\+\$,\w]+))(?:([.-;:&=\+\$,\w\/]*))$
/
gm

Description

Validates that all necessary parts of a "normal" domain are there (scheme, subdomain, secondary-level domain, top-level domain) and allows for additional subdirectories. Does not work for options like "mailto: example@email.com" or anything that does not stick to a typical web address URL.

Submitted by Alexa J. - 2 years ago