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

/
/
gms

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/^var (.*?Infos) = .*?data: (.*?),$/ms'; $str = 'var syntheticResponseTimeDistributionInfos = { data: {"result": {"minY": 1.0, "minX": 0.0, "ticks": [[0, "Requests having \\nresponse time <= 500ms"], [1, "Requests having \\nresponse time > 500ms and <= 1,500ms"], [2, "Requests having \\nresponse time > 1,500ms"], [3, "Requests in error"]], "maxY": 37.0, "series": [{"data": [[0.0, 37.0]], "color": "#9ACD32", "isOverall": false, "label": "Requests having \\nresponse time <= 500ms", "isController": false}, {"data": [], "color": "yellow", "isOverall": false, "label": "Requests having \\nresponse time > 500ms and <= 1,500ms", "isController": false}, {"data": [], "color": "orange", "isOverall": false, "label": "Requests having \\nresponse time > 1,500ms", "isController": false}, {"data": [[3.0, 1.0]], "color": "#FF6347", "isOverall": false, "label": "Requests in error", "isController": false}], "supportsControllersDiscrimination": false, "maxX": 3.0, "title": "Synthetic Response Times Distribution"}}, getOptions: function() { return { var activeThreadsOverTimeInfos = { data: {"result": {"minY": 1.0, "minX": 1.5931058172E12, "maxY": 1.0, "series": [{"data": [[1.5931058186E12, 1.0], [1.5931058196E12, 1.0], [1.5931058175E12, 1.0], [1.5931058185E12, 1.0], [1.5931058195E12, 1.0], [1.5931058205E12, 1.0], [1.5931058184E12, 1.0], [1.5931058194E12, 1.0], [1.5931058204E12, 1.0], [1.5931058173E12, 1.0], [1.5931058183E12, 1.0], [1.5931058193E12, 1.0], [1.5931058203E12, 1.0], [1.5931058172E12, 1.0], [1.5931058213E12, 1.0], [1.5931058192E12, 1.0], [1.5931058202E12, 1.0], [1.5931058212E12, 1.0], [1.5931058181E12, 1.0], [1.5931058191E12, 1.0], [1.5931058201E12, 1.0], [1.5931058211E12, 1.0], [1.593105818E12, 1.0], [1.593105819E12, 1.0], [1.59310582E12, 1.0], [1.593105821E12, 1.0], [1.5931058179E12, 1.0], [1.5931058189E12, 1.0], [1.5931058209E12, 1.0], [1.5931058178E12, 1.0], [1.5931058198E12, 1.0], [1.5931058208E12, 1.0], [1.5931058177E12, 1.0], [1.5931058187E12, 1.0], [1.5931058197E12, 1.0], [1.5931058207E12, 1.0], [1.5931058176E12, 1.0]], "isOverall": false, "label": "ThreadGroup", "isController": false}, {"data": [[1.5931058224E12, 1.0], [1.5931058217E12, 1.0]], "isOverall": false, "label": "tearDown Thread Group", "isController": false}], "supportsControllersDiscrimination": false, "granularity": 100, "maxX": 1.5931058224E12, "title": "Active Threads Over Time"}}, getOptions: function() { '; $subst = "var $1 = {\n data: $1_data,"; $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