Regular Expressions 101

Community Library Entry

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 - a year ago (Last modified a year ago)