Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
(http|https)\:\/\/(?:(.+?)(?:\:(.+?))?\@)?((?:[\w-]+\.)+)([A-Za-z0-9]+)(?:\:(\d{2,5}))?((?:\/[\w-%.]*)+)?(\?(?:[\w-%&="'+,]+)?)?(\#(?:[^#]+)?)?
/

Description

Gets all parts of URL including port, username, password, fragment, query, and path

Submitted by Vihan Bhargava - 9 years ago