Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • 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
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • 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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^https?:\/\/www\.google((\..{1,3}){1,2})\/(search\?)(?!flights|maps)(?!.*&tbm=(shop|fin|lcl)&).*/m'; $str = '#images https://www.google.com/search?q=finance&hl=en&tbm=isch&sxsrf=ALeKk03-wtxJ6IxBQ1QplyRfSUR5Zq6p5w:1588804525013&source=lnms&sa=X&ved=0ahUKEwjsstKKpqDpAhWIiqQKHeGbDWcQ_AUICygC&biw=2560&bih=1307&dpr=1 #books https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk020ZKe6S8ZciwePz_FDqQNjlrIyMw:1588804501205&source=lnms&tbm=bks&sa=X&ved=2ahUKEwiuraX_paDpAhUHLBoKHbvWAKYQ_AUoAXoECBgQCQ&biw=2560&bih=1307 #all https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk02-xP9nE6zHjjatj9fSG3th2_3zzw:1588804479887&source=lnms&sa=X&ved=0ahUKEwi0k5D1paDpAhWJ-qQKHW1XANcQ_AUIDSgA&biw=2560&bih=1307&dpr=1 #news https://www.google.com/search?q=finance&source=lmns&tbm=nws&bih=1307&biw=2560&hl=en&ved=2ahUKEwi2jsnCpaDpAhWF44UKHcvnDusQ_AUoAXoECAEQAQ ####Dont match following #finance https://www.google.com/search?hl=en&biw=2560&bih=1307&tbm=fin&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ%3A1588802138647&ei=WjKzXuX1JofVkwWv-p24Dg&q=finance&oq=finance&gs_l=finance-immersive.3...980.1734.0.1817.7.5.0.0.0.0.208.208.2-1.1.0....0...1.1.64.finance-immersive..6.1.208...81.0.T31TXEhQon8 #flights https://www.google.com/flights?q=testt&bih=1307&biw=2560&hl=en&tbm=flm&sxsrf=ALeKk03tMI1tx59I3Jc-LJfPj3_gEihKyA:1588801776819&source=lnms&sa=X&ved=0ahUKEwiugJrsm6DpAhVNDOwKHRFgCLkQ_AUINSgD#flt=/m/04jpl..2020-05-22*./m/04jpl.2020-05-26;c:GBP;e:1;ls:1w;sd:0;t:h #maps https://www.google.com/maps?hl=en&biw=2560&bih=1307&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ:1588802138647&q=finance&um=1&ie=UTF-8&sa=X&ved=2ahUKEwiY2IGanaDpAhVFCewKHYSIDCwQ_AUoAHoECAEQCA #maps widget in search https://www.google.com/search?q=finance&source=lmns&bih=1307&biw=2560&hl=en&ved=2ahUKEwjd86Po7qLpAhWFs3EKHVkiBy0QvS4wDnoECBEQHQ&sxsrf=ALeKk02paj14dQam1LLme0LY76me3nxOSw:1588892768213&npsic=0&rflfq=1&rlha=0&rllag=52234121,132579,226&tbm=lcl&rldimm=12043644416834703012&lqi=CgdmaW5hbmNlWhIKB2ZpbmFuY2UiB2ZpbmFuY2U&rldoc=1&tbs=lrf:!1m4!1u3!2m2!3m1!1e1!1m4!1u16!2m2!16m1!1e1!1m4!1u16!2m2!16m1!1e2!2m1!1e16!2m1!1e3!3sIAE,lf:1,lf_ui:2&rlst=f#rlfi=hd:;si:12043644416834703012,l,CgdmaW5hbmNlWhIKB2ZpbmFuY2UiB2ZpbmFuY2U;mv:[[54.130455193219696,5.088306911880459],[50.21534923934904,-6.66706418186956]] #shopping https://www.google.com/search?q=testt&source=lmns&tbm=shop&bih=1307&biw=2560&hl=en&ved=2ahUKEwiShpzrm6DpAhUW_hoKHQ61AEcQ_AUoAnoECAEQAg https://www.google.com/ https://www.google.fr/ https://www.google.cm/ https://www.google.co.uk/'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php