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 = '/(\d{5,}\S+)(?:-REV)|(\d{5,})|(\d.+)(?:-REV).+|(\b[A-Za-z0-9]+-[A-Za-z0-9]+-[A-Za-z0-9]+\b)|(\d{4,}.\S+)/m'; $str = 'SIEMENS10249071REV05 22D1496-REV-A SANTASISE398FOP4 KCC C318-M-2328 22006-17114-REV-0 WELD30 2328ENDFIN OSH4780973 10520398ITEM7 KCC C153-M-136290 2373 TAPER SANTA ISE398 R2 SANTASISE398RGH1 34F0-010-102-REV-WELDMENT 14A1936D1F1-REV-NONE 6181194-REV-B PRETE WT-80-1015BLIND MAXAM340000566 SHARPE-36465 1ST OSH 3899580 7494-03-301-REV-NONE MAXAM340000566OP2 KCC C318-M-2373TAPER CARDINAL36465 SIEMENS-10248227 REV.8 4212.8842-REV-Q 14A1936-REV-NONE LATHE TOOL 360 YIELD 450111 RH MAIN PROGRAM;360 YIELD 450111 LH MAIN PROGRAM;450111 KCC C318-M-2373 360 YIELD 450211 RH MAIN PROGRAM;360 YIELD 450211 LH MAIN PROGRAM;450211 360 YIELD 450101 LH MAIN PROGRAM;450101 10753289-REV-02 30613D3-REV-05 30613D4-REV-05 OSHKOSH CORP/4381568/REV B/OP 1 OSHKOSH/12611249/REV A/OP1 14A1669 COVER-REV-J OSH 4641290 KCC C318-M-2372 2328 FINISH 10751755-REV-2 312-133001-001-REV-D KOOTR KT300AL OP1 OSHKOSH CORP/4381568/REV B/OP 2 360 YIELD 450201 LH MAIN PROGRAM;360 YIELD 450201 RH MAIN PROGRAM;450201 OSH 3899580OP2 10520398ITEM17 WELD30BIG 2347337-01-REV-NONE 2372 FINISH 10753199-02-REV-7 OSH 1693510 2328END OSH 4384499OP2 E4-TKD-Z002A00KP;E4-TKD-ZOO2AOO WITH TRANSFER 10753199-02-REV-6 OSH 4384499 7494-04-103-REV-NONE 14A1669D2F1-REV-J 4212.8801-REV-O 2373 FINISH 2372 TAPER SHARPE-36465 2ND KOOTR KT300AL OP2 312-133034-001-REV-B 14A1937-REV-01 OSHKOSH/12611249/REV A/OP2 SANTASISE398FOP3 SIEMENS10248226REV08 '; 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