Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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 = '/(>.*?)\QStyle\E([^=][^<]*)/m'; $str = '<div><p style="text-align:left;">Style: <span style="float:right;">Casual</span></p></div><div><p style="text-align:left;">Color: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">Sleeve Length: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>Sleeve Length </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table>'; $subst = "$1MODIFIED_COLOR$2"; $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