Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests (62)

Tools

Sponsors
An explanation of your regex will be automatically generated as you type.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gi

Unit Tests

given the string https://www.example1.com assert that regex does match
given the string https://blog.example2.org assert that regex does match
given the string http://www.subdomain.example3.net assert that regex does match
given the string https://shop.example4.co.uk assert that regex does match
given the string https://forum.example5.info assert that regex does match
given the string https://www.example6.gov assert that regex does match
given the string https://news.example7.edu assert that regex does match
given the string http://blog.example8.tv assert that regex does match
given the string https://www.subdomain1.example9.biz assert that regex does match
given the string https://subdomain2.example10.name assert that regex does match
given the string https://www.example11.pro assert that regex does match
given the string https://shop.example12.asia assert that regex does match
given the string http://forum.example13.museum assert that regex does match
given the string https://blog.example14.aero assert that regex does match
given the string https://www.example15.jobs assert that regex does match
given the string https://www.subdomain1.example16.coop assert that regex does match
given the string https://subdomain2.example17.mobi assert that regex does match
given the string http://www.example18.int assert that regex does match
given the string https://forum.example19.tel assert that regex does match
given the string https://www.example20.travel assert that regex does match
given the string https://blog.example21.cat assert that regex does match
given the string https://shop.example22.xxx assert that regex does match
given the string http://www.subdomain1.example23.tel assert that regex does match
given the string https://subdomain2.example24.museum assert that regex does match
given the string https://www.example25.name assert that regex does match
given the string https://subdomain1.example26.biz assert that regex does match
given the string http://blog.example27.aero assert that regex does match
given the string https://forum.example28.asia assert that regex does match
given the string https://www.example29.pro assert that regex does match
given the string https://subdomain1.example30.info assert that regex does match
given the string https://subdomain2.example31.coop assert that regex does match
given the string http://www.example32.jobs assert that regex does match
given the string https://shop.example33.travel assert that regex does match
given the string https://blog.example34.mobi assert that regex does match
given the string https://www.example35.int assert that regex does match
given the string http://forum.example36.xxx assert that regex does match
given the string https://www.subdomain1.example37.cat assert that regex does match
given the string https://subdomain2.example38.edu assert that regex does match
given the string https://www.example39.tv assert that regex does match
given the string http://blog.example40.aero assert that regex does match
given the string https://shop.example41.museum assert that regex does match
given the string https://www.subdomain1.example42.name assert that regex does match
given the string https://subdomain2.example43.coop assert that regex does match
given the string http://www.example44.info assert that regex does match
given the string https://forum.example45.biz assert that regex does match
given the string https://www.example46.tel assert that regex does match
given the string https://subdomain1.example47.travel assert that regex does match
given the string https://subdomain2.example48.cat assert that regex does match
given the string http://www.example49.xxx assert that regex does match
given the string https://blog.example50.mobi assert that regex does match
given the string htp://www.invalid1.com assert that regex does not match
given the string ftp://example2.org assert that regex does not match
given the string http://www.invalid3..net assert that regex does not match
given the string https://shop.example4 assert that regex does not match
given the string http://www_subdomain.invalid6 assert that regex does not match
given the string https://www.invalid7.edu. assert that regex does not match
given the string http://blog..example8.tv assert that regex does not match
given the string https://www_subdomain1.invalid9.biz assert that regex does not match
given the string https://subdomain2.example10. assert that regex does not match
given the string https://invalid-url. assert that regex does not match
given the string https://www.exemplo.com/pagina?query1=va… assert that regex does match
given the string https://www.exemplo.com/pagina-dinamica?… assert that regex does match