Regular Expressions 101

Community Patterns

URL Match and split

1

Regular Expression
PCRE (PHP <7.3)

~
(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))
~
i

Description

match any type of url and split each part (protocol, domain, page, GET, and ID) in capture groups

Submitted by anonymous - 8 years ago