Regular Expressions 101

Save & Share

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

Substitution

Processing...

Code Generator

Generated Code

$re = '/D601-10689-PC01/m'; $str = 'iPhone1,1 iPhone1,2 iPhone2,1 iPhone3,1 iPhone3,2 iPhone3,3 iPhone4,1 iPhone5,1 iPhone5,2 iPhone5,3 iPhone5,4 iPhone6,1 iPhone6,2 iPhone7,2 iPhone7,1 iPhone8,1 iPhone8,2 iPhone8,4 iPhone9,1 iPhone9,3 iPhone9,2 iPhone9,4 iPhone10,1 iPhone10,4 iPhone10,2 iPhone10,5 iPhone10,3 iPhone10,6 iPhone11,8 iPhone11,2 iPhone11,6 iPhone11,4 iPhone12,1 iPhone12,3 iPhone12,5 iPhone12,8 iPhone13,1 iPhone13,2 iPhone13,3 iPhone13,4 iPhone14,4 iPhone14,5 iPhone14,2 iPhone14,3 iPhone14,6 iPad1,1 iPad1,1 iPad2,1 iPad2,2 iPad2,3 iPad2,4 iPad2,5 iPad2,6 iPad2,7 iPad3,1 iPad3,2 iPad3,3 iPad3,4 iPad3,5 iPad3,6 iPad4,1 iPad4,2 iPad4,3 iPad4,4 iPad4,5 iPad4,6 iPad4,7 iPad4,8 iPad4,9 iPad5,1 iPad5,2 iPad5,3 iPad5,4 iPad6,11 iPad6,12 iPad6,3 iPad6,4 iPad6,7 iPad6,8 iPad7,1 iPad7,11 iPad7,12 iPad7,12 iPad7,12 iPad7,2 iPad7,3 iPad7,4 iPad7,5 iPad7,6 iPad8,1 iPad8,10 iPad8,10 iPad8,10 iPad8,11 iPad8,12 iPad8,12 iPad8,12 iPad8,2 iPad8,3 iPad8,3 iPad8,3, iPad8,4 iPad8,4 iPad8,4 iPad8,5, iPad8,6 iPad8,7 iPad8,7 iPad8,7 iPad8,8 iPad8,8 iPad8,8 iPad8,9 iPad11,1 iPad11,2 iPad11,2 iPad11,2 iPad11,3 iPad11,4 iPad11,4 iPad11,4 iPad11,6 iPad11,7 iPad11,7 iPad11,7 iPad12,1 iPad12,2 iPad12,2 iPad12,2 iPad13,1 iPad13,10 iPad13,11 iPad13,16 iPad13,17 iPad13,17 iPad13,2 iPad13,2 iPad13,2 iPad13,4 iPad13,5 iPad13,6 iPad13,7 iPad13,8 iPad13,9 iPad14,1 iPad14,2 iPad14,2 AppleTV1,1 AppleTV2,1 AppleTV3,1 AppleTV3,2 AppleTV5,3 AppleTV6,2 AppleTV11,1'; $subst = ""; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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