Regular Expressions 101

Community Patterns

1...56789...589

URL

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(((ht|f)(tp)(s)?(:\/\/))?(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))(:\d{1,5})?((\/)([\w\.~%-]+))*(\/)?((\?)(([\w]+)(=[\w\.~%-]+)?((&)([\w]+)(=[\w\.~%-]+)?)*)?)?((#)((([\w]+(=[\w\,\*\.~%-]+)?)(&[\w]+(=[\w\,\*\.~%-]+)?)*)|(:~:text=([\w\.~%-]+\,)?([\w\.~%-]+)(\,[\w\.~%-]+){0,2}))?)?)$
/
gm

Description

Support any types of URL for https and http protocol.

  • http or https [optional]
  • domain name [mandatory]
  • file path [optional]
  • query parameter [optional]
Submitted by 17Hieng - 5 months ago (Last modified 5 months ago)