Regular Expressions 101

Save & Share

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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/((?:(?:123456)|(?:1[2-5]*)|(?:[2-5]*6)) )/m'; $str = '12456 123456 34 1236 123456 1234 45 123456 whitings 14 356 124 6 12345 6 1245 malformations 12456 23456 2356 12345 12345 123456 6 furnishings 12456 34 34 356 12356 15 26 13 gastrointestinal 23456 1 234 3 5 12356 lawyer 2356 345 12345 4 4 1 6 gripped 1 236 145 23 16 4 12356 4 3 packers 1245 146 2 2 23 126 1235 2356 4 3 outrun should not match ^ 123456 123456 123456 123456 35 12456 123456 123456 23 356 23456 25 replenishes 3456 45 35 12456 1346 256 2356 123456 1236 123456 1346 flophouse 356 123456 56 12356 4 3 2356 6 12456 1246 12356 footsteps 123456 156 2356 136 123456 146 123456 5 12356 123456 1456 expurgations 12346 2 2346 123456 2356 56 245 12346 13456 12456 misidentifies 1256 345 24 12456 12356 123456 12356 356 1256 5 26 swine 123456 45 456 12346 136 12346 6 24 12346 4 56 235 extremists 346 1236 2356 13456 123456 23456 1346 1256 123456 24 346 245 hexagonal 14 23456 12356 1234 15 1456 1245 123456 23456 chrysanthemums 245 34 123456 123456 12 346 134 4 245 1245 146 6 gravitate 346 1245 136 23456 5 1356 123456 5 123456 123456 octettes 134 3456 15 15 46 34 123456 123456 3456 246 quasar 123456 35 123456 123456 123456 1245 123456 12456 1 surprisings 356 12346 1246 1235 4 12356 2 13456 13456 236 emptied 23456 2356 12456 134 2356 256 12456 12346 1 13 ennoblement 123456 235 16 5 13456 15 2 1456 12356 3456 3 123456 quadratic should match ^'; 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