Regular Expressions 101

Community Patterns

Community Library Entry

-1

Regular Expression
PCRE (PHP <7.3)

/
^(?:(?'scheme'http[s]?):\/\/)?(?'host'[a-z0-9_\-.]+)(?:\:(?'port'[0-9]+))?(?'path'\/[^\?\s]*)?(?:\?(?'query'\S+))?
/
gm

Description

This is regex for website url matching scheme,host,port,path and query. I did it because in c#, class Uri does not understand urls without scheme and says that 'google.com' is invalid url.

Submitted by anonymous - 7 years ago