Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update 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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
gmi

Test String

Code Generator

Generated Code

$re = '/\b(?:(?:[A-Z][A-HJ-Y]?[0-9][0-9A-Z]?|ASCN|STHL|TDCU|BBND|[BFS]IQ{2}|GX11|PCRN|TKCA) ?[0-9][A-Z]{2}|GIR ?0A{2}|SAN ?TA1|AI-?[0-9]{4}|BFPO[ -]?[0-9]{2,3}|MSR[ -]?1(?:1[12]|[23][135])0|VG[ -]?11[1-6]0|[A-Z]{2} ? [0-9]{2}|KY[1-3][ -]?[0-2][0-9]{3})\b/mi'; $str = 'M1 1AA M60 1NW CR2 6XH DN55 1PT GY101ZZ W1A 1HQ EC1A 1BB CW3 9SS SE5 0EG SE50EG se5 0eg WC2H 7LT BS98 1TL BX1 1LT BX2 1LB BX3 2BB BX4 7SB BX5 5AT CF10 1BH CF99 1NA CV4 8UW CV35 0DB DA1 1RT DE99 3GG DE55 4SW DH98 1BT DH99 1NS E14 5HQ E14 5JP E16 1XL E20 2AQ E20 2BB E20 2ST E20 3BS E20 3EL E20 3ET E20 3HB E20 3HY E98 1SN E98 1ST E98 1TT EC2N 2DB EC4Y 0HQ EH12 1HQ EH99 1SP G58 1SB GIR 0AA IV21 2LR L30 4GB LS98 1FD M50 2BH M50 2QH N1 9GU N81 1ER NE1 4ST NG80 1EH NG80 1LH NG80 1RH NG80 1TH MSR1110 MSR1120 MSR1210 MSR1230 MSR1250 MSR1310 MSR1330 MSR1350 PH1 5RB PH1 2SJ S2 4SU S6 1SW SB 01 VG1110 S14 7UP SE1 0NE SE1 8UJ SM6 0HB SN38 1NW SR5 1SU SW1A 0AA WC1N2PL SW1A 0PW SW1A 1AA SW1A 2AA SW1A 2AB SW1H 0TL SW1P 3EU SW1W 0DT TW8 9GS W1A 1AA W1D 4FA W1N 4DJ W1T 1FB CO4 3SQ SAN TA1 '; 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