Regular Expressions 101

Community Patterns

Parse URL by subcomponent

0

Regular Expression
PCRE (PHP <7.3)

/
^(?<Scheme>[file|ftp|https{0,1}|ldap|telnet]+:\/{2})?(?<Subdomain>[a-zA-Z0-9-]{0,4}\.)?(?<Domain>\w+\.\w+\.?\w+\/)(?<Subdirectory>@[\w.]+\/)?(?<Path>[\w_~.-]+\/?[\w_-]+\/{0,1}?[\w_~.-]+)(?<Query>[%?&;].[\w&_~.=-]+)?(?<Fragment>#?[\/\w_-~.,=&-]+)?$
/
gm

Description

Loading markdown...
Submitted by Syd Salmon - 4 years ago