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

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

/
/
g

Test String

Code Generator

Generated Code

$re = '/(\s|\S){0,40}\"([0-9]{1,3})\"\;\}/'; $str = 'a:1:{s:2:"gr";s:3:"214";} a:1:{s:2:"gr";s:3:"188";} a:1:{s:2:"gr";s:3:"213";} a:1:{s:2:"gr";s:3:"169";} a:1:{s:2:"gr";s:3:"219";} a:1:{s:2:"gr";s:3:"221";} a:1:{s:2:"gr";s:3:"211";} a:1:{s:2:"gr";s:3:"184";} a:1:{s:2:"gr";s:3:"191";} a:1:{s:2:"gr";s:2:"16";} a:1:{s:2:"gr";s:3:"127";} a:1:{s:2:"gr";s:3:"217";} a:1:{s:2:"gr";s:3:"200";} a:1:{s:2:"gr";s:3:"182";} a:1:{s:2:"gr";s:3:"128";} a:1:{s:2:"gr";s:2:"17";} a:1:{s:2:"gr";s:3:"163";} a:1:{s:2:"gr";s:3:"212";} a:1:{s:2:"gr";s:3:"166";} a:1:{s:2:"gr";s:2:"94";} a:1:{s:2:"gr";s:2:"83";} a:1:{s:2:"gr";s:2:"27";} a:1:{s:2:"gr";s:2:"28";} a:1:{s:2:"gr";s:3:"167";} a:1:{s:2:"gr";s:3:"168";} a:1:{s:2:"gr";s:3:"202";} a:1:{s:2:"gr";s:1:"7";} a:1:{s:2:"gr";s:3:"129";} a:1:{s:2:"gr";s:3:"183";} a:1:{s:2:"gr";s:2:"26";} a:1:{s:2:"gr";s:3:"185";} a:1:{s:2:"gr";s:3:"175";} a:1:{s:2:"gr";s:2:"29";} a:1:{s:2:"gr";s:3:"209";} a:1:{s:2:"gr";s:3:"177";} a:1:{s:2:"gr";s:3:"178";} a:1:{s:2:"gr";s:2:"24";} a:1:{s:2:"gr";s:3:"225";} a:1:{s:2:"gr";s:3:"224";} a:1:{s:2:"gr";s:2:"57";} a:1:{s:2:"gr";s:2:"18";} a:1:{s:2:"gr";s:3:"208";} a:1:{s:2:"gr";s:3:"193";} a:1:{s:2:"gr";s:2:"33";} a:1:{s:2:"gr";s:2:"10";} a:1:{s:2:"gr";s:2:"11";} a:1:{s:2:"gr";s:2:"12";} a:1:{s:2:"gr";s:3:"173";} a:1:{s:2:"gr";s:2:"13";} a:1:{s:2:"gr";s:2:"14";} a:1:{s:2:"gr";s:1:"9";} a:1:{s:2:"gr";s:2:"15";} a:1:{s:2:"gr";s:3:"195";} a:1:{s:2:"gr";s:3:"130";} a:1:{s:2:"gr";s:2:"25";} a:1:{s:2:"gr";s:2:"50";} a:1:{s:2:"gr";s:3:"131";} a:1:{s:2:"gr";s:2:"96";} a:1:{s:2:"gr";s:2:"19";} a:1:{s:2:"gr";s:3:"107";} a:1:{s:2:"gr";s:3:"116";} a:1:{s:2:"gr";s:3:"364";} a:1:{s:2:"gr";s:3:"194";} a:1:{s:2:"gr";s:2:"44";} a:1:{s:2:"gr";s:3:"171";} a:1:{s:2:"gr";s:3:"172";} a:1:{s:2:"gr";s:3:"170";} a:1:{s:2:"gr";s:2:"20";} a:1:{s:2:"gr";s:2:"95";} a:1:{s:2:"gr";s:2:"84";} a:1:{s:2:"gr";s:2:"22";} a:1:{s:2:"gr";s:2:"23";} a:1:{s:2:"gr";s:2:"67";} a:1:{s:2:"gr";s:3:"118";} a:1:{s:2:"gr";s:2:"97";} a:1:{s:2:"gr";s:1:"6";} a:1:{s:2:"gr";s:3:"365";} a:1:{s:2:"gr";s:3:"190";} a:1:{s:2:"gr";s:2:"82";} a:1:{s:2:"gr";s:2:"42";} a:1:{s:2:"gr";s:2:"74";} a:1:{s:2:"gr";s:2:"76";} a:1:{s:2:"gr";s:2:"73";} a:1:{s:2:"gr";s:2:"78";} a:1:{s:2:"gr";s:2:"68";} a:1:{s:2:"gr";s:3:"207";} a:1:{s:2:"gr";s:3:"197";} a:1:{s:2:"gr";s:2:"77";} a:1:{s:2:"gr";s:2:"46";} a:1:{s:2:"gr";s:2:"51";} a:1:{s:2:"gr";s:3:"206";} a:1:{s:2:"gr";s:3:"165";} a:1:{s:2:"gr";s:2:"60";} a:1:{s:2:"gr";s:2:"61";} a:1:{s:2:"gr";s:2:"62";} a:1:{s:2:"gr";s:3:"187";} a:1:{s:2:"gr";s:3:"176";} a:1:{s:2:"gr";s:3:"196";} a:1:{s:2:"gr";s:3:"223";} a:1:{s:2:"gr";s:3:"117";} a:1:{s:2:"gr";s:2:"98";} a:1:{s:2:"gr";s:2:"47";} a:1:{s:2:"gr";s:3:"198";} a:1:{s:2:"gr";s:2:"45";} a:1:{s:2:"gr";s:3:"203";} a:1:{s:2:"gr";s:3:"205";} a:1:{s:2:"gr";s:3:"201";} a:1:{s:2:"gr";s:3:"115";} a:1:{s:2:"gr";s:2:"58";} a:1:{s:2:"gr";s:3:"204";} a:1:{s:2:"gr";s:3:"132";} a:1:{s:2:"gr";s:2:"48";} a:1:{s:2:"gr";s:2:"49";} a:1:{s:2:"gr";s:2:"99";} a:1:{s:2:"gr";s:3:"594";} a:1:{s:2:"gr";s:3:"585";} a:1:{s:2:"gr";s:3:"368";} a:1:{s:2:"gr";s:2:"81";} a:1:{s:2:"gr";s:2:"53";} a:1:{s:2:"gr";s:2:"52";} a:1:{s:2:"gr";s:3:"180";} a:1:{s:2:"gr";s:3:"181";} a:1:{s:2:"gr";s:3:"179";} a:1:{s:2:"gr";s:3:"164";} a:1:{s:2:"gr";s:3:"186";} a:1:{s:2:"gr";s:3:"174";} a:1:{s:2:"gr";s:3:"199";} a:1:{s:2:"gr";s:3:"210";} a:1:{s:2:"gr";s:3:"369";} a:1:{s:2:"gr";s:3:"370";} a:1:{s:2:"gr";s:3:"371";} a:1:{s:2:"gr";s:3:"372";} a:1:{s:2:"gr";s:3:"373";} a:1:{s:2:"gr";s:3:"374";} a:1:{s:2:"gr";s:3:"375";}'; 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