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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/\s(.*)/m'; $str = 'England have not done this since 30 July, 1966. This remains the golden date in the country\'s football calendar, one that has never come close to being equalled in the subsequent 55 agonising years. Germany were beaten by England at the knockout stage of a major tournament for the first time since that World Cup final as Gareth Southgate\'s side ran out deserved 2-0 winners at a joyous, nervy, celebratory Wembley. And now the door has been pushed open a little further to give England the chance to do something else they have not done since 1966 - reach the final of a major tournament. Germany, who have beaten England so often since that day in 1966, were overcome as Southgate earned vindication for both his tactics and his faith in captain Harry Kane, who rescued another largely average personal display with a moment of glorious release and relief when he headed home the second goal to open his account in Euro 2020. \'Nights like this allow England to dream\' - Alan Shearer column England end 55-year wait for knockout win over Germany Who stands between England and the Euros final? \'It\'s a special moment for me\' - Raheem Sterling And to add to the landmarks, this was the first time England have won a match (as opposed to progressing on penalties) at the knockout stage of any European Championships. A grim statistic best erased. '; 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