Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
g

Test String

Code Generator

Generated Code

$re = '/"([^"]+)"\s*\(([^\)]+)\)\s*\d+\/\s*\d+\/(\d+)/'; $str = '1X79 "The X-Files" (1.01) 9/10/93 1/17/94* 11/ 6/94* 1X01 "Deep Throat" (1.02) 9/17/93 12/24/93 6/24/94 1X02 "Squeeze" (1.03) 9/24/93 12/ 3/93 6/10/94 11/ 4/95* 1X03 "Conduit" (1.04) 10/ 1/93 12/14/93* 5/27/94 1X04 "Jersey Devil" (1.05) 10/ 8/93 12/31/93 7/22/94 1X05 "Shadows" (1.06) 10/22/93 3/ 4/94 5/26/95 1X06 "Ghost in the Machine" (1.07) 10/29/93 1/14/94 1X07 "Ice" (1.08) 11/ 5/93 1/17/94* 8/12/94 3/ 3/95 1X08 "Space" (1.09) 11/12/93 1/28/94 8/22/94* 1X09 "Fallen Angel" (1.10) 11/19/93 3/29/94* 11/13/94* 1X10 "Eve" (1.11) 12/10/93 3/11/94 8/26/94 1X11 "Fire" (1.12) 12/17/93 3/25/94 11/20/94* 1X12 "Beyond the Sea" (1.13) 1/ 7/94 4/ 8/94 12/22/95? 1X13 "GenderBender" (1.14) 1/21/94 5/20/94 7/21/95 1X14 "Lazarus" (1.15) 2/ 4/94 6/ 3/94 9/ 2/94 1X15 "Young at Heart" (1.16) 2/11/94 6/17/94 8/19/94 1X16 "E.B.E." (1.17) 2/18/94 7/ 8/94 11/27/94* 1X17 "Miracle Man" (1.18) 3/18/94 7/ 1/94 1X18 "Shapes" (1.19) 4/ 1/94 10/28/94 8/ 4/95 1X19 "Darkness Falls" (1.20) 4/15/94 8/ 5/94 12/ 2/94 1X20 "Tooms" (1.21) 4/22/94 7/15/94 11/ 4/95* 1X21 "Born Again" (1.22) 4/29/94 8/22/94* 1X22 "Roland" (1.23) 5/ 6/94 7/29/94 1X23 "The Erlenmeyer Flask" (1.24) 5/13/94 9/ 9/94 9/ 1/95'; 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