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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

$re = '/^(?P<unit_type>SF)(?P<unit_size>500|400|350|300|250|200|150|125)(?P<mounting_type>A|B|K)(?P<decompression_feature>0|1)(?P<sep_1>-)(?P<cracking_pressure>1)(?P<sep_2>-)(?P<unit_series>4X)(?P<sep_3>/)(?P<type_of_limit_switch>Q2|)(?P<power_supply_of_limit_switch>G24Z|)(?P<seal_material>|)(?P<pipe_port>|)(?P<special_version>SO102|SO104|)(?P<additional_details>(.|[0-9])*)$/m'; $str = 'SF200A1-1-4X/ SF250A1-1-4X/ SF400A1-1-4X/ SF200K0-1-4X/ SF150A1-1-4X/ SF125B1-1-4X/ SF125A1-1-4X/ SF200B1-1-4X/ SF150B1-1-4X/ SF250B1-1-4X/ SF250A0-1-4X/ SF150A0-1-4X/ SF300A1-1-4X/ SF200K0-1-4X/SO72 SF125A0-1-4X/ SF300A0-1-4X/ SF300B1-1-4X/ SF350A0-1-4X/ SF250K0-1-4X/ SF200A0-1-4X/ SF150K0-1-4X/ SF125B0-1-4X/ SF150B0-1-4X/ SF200B0-1-4X/ SF350A1-1-4X/ SF500A1-1-4X/ SF150K0-1-4X/SO72 SF125K0-1-4X/ SF400A0-1-4X/ SF250B0-1-4X/ SF350B1-1-4X/ SF300K0-1-4X/ SF250K0-1-4X/SO72 SF300K0-1-4X/SO72 SF300B0-1-4X/ SF250B1-1-4X/SO103 SF125K0-1-4X/V SF125B1-1-4X/SO103 SF400B1-1-4X/ SF125A1-1-4X/SO103 SF200A1-1-4X/SO103 SF150B1-1-4X/V SF250A1-1-4X/SO103 SF150B1-1-4X/SO103 SF200K0-1-4X/SO103 SF300K0-1-4X/V SF350B0-1-4X/ SF150A0-1-4X/V SF150A1-1-4X/SO103 SF150A0-1-4X/Q2G24 SF200A0-1-4X/Q2G24 SF250A0-1-4X/Q2G24 SF300A0-1-4X/Q2G24 SF400A0-1-4X/Q2G24 SF500B1-1-4X/ SF125A0-1-4X/Q2G24 SF250A0-1-4X/V SF350A0-1-4X/Q2G24 SF350A1-1-4X/V SF125A1-1-4X/V SF500A0-1-4X/Q2G24 SF125A0-1-4X/Q2G24SO103 SF250K0-1-4X/SO92 SF200B1-1-4X/SO103 SF150B0-1-4X/500 SF150A0-1-4X/500 SF200B0-1-4X/500 SF200A0-1-4X/500 SF250B0-1-4X/500 SF250A0-1-4X/500 SF300A0-1-4X/500 SF300B0-1-4X/500 SF500A1-1-4X/Q2G24 SF200A0-1-4X/500Q2G24 SF300A0-1-4X/500Q2G24 SF400B0-1-4X/ SF400A1-1-4X/Q2G24 SF250A0-1-4X/SO43A1840 '; 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