Regular Expressions 101

Community Patterns

URL supporting ports, GET params and js routing

1

Regular Expression
PCRE (PHP <7.3)

/
^(http(s)?:\/\/)(([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)+(:[1-9]+[0-9]*)?)(\/?|((\/(#?[a-zA-Z_\-\.])+)*)(\/?|\?([a-z]+\=([a-z]+|[a-z]+,[a-z]+)*&)*([a-z]+\=([a-z]+|[a-z]+,[a-z]+)*)\/?))$
/

Description

(http(s)?://) // http:// or https://

(([a-zA-Z0-9_-])+(.([a-zA-Z0-9_-])+)+(:[1-9]+[0]*)?)(/?| // basic url f.e. www.wp.pl with obligatory / at end

((/(#?[a-zA-Z_-.])+)*)(/?| // subfolders or asp files plus possible # for routing or anchor with obligatory / at end

?([a-z]+=([a-z]+|[a-z]+,[a-z]+)&)([a-z]+=([a-z]+|[a-z]+,[a-z]+)*)/?)) // http GET parameters with obligatory / at end

Submitted by Rafał Rowiński - 9 years ago