Regular Expressions 101

Community Patterns

1...34567...902

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)$
/
gm

Description

Use to validate basic website URLs with or without http://. I took bits and pieces of other regexes I found and compiled into one that worked well for my purposes.

Submitted by Daniel Ecker - 2 years ago