Regular Expressions 101

Save & Share

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 = '/((?<="pressure".."pressure")[^"]+(?=")\"*[a-zA-Z]+"[,]\s+)(\d)[.](\d)(\d+)(,[^\d])(([-]\d+).(\d)(\d+)),[^\d]/m'; $str = '"0x03": [ ["Q1000 LPG", "P94_0_00", 0, 0, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0.1, "False", 1.5618, 0.0, 0.0, 5.0, "[10.0, None]", "Lps"], ["P1000 LPG Tank", "P94_0_01", 0, 1, "0x30","0x03", 0, "pressure", "pressure", [], 0.0,0.0, 0.1, "True", 1.5633, -1.1520, 0.0, 5.0, "[10.0, \'None\']", "MPa"], ["P1004 LPG Injector", "P94_0_02", 0, 2, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0.1, "True", 3.1146, -2.3736, 0.0, 10.0, "[10.0, \'None\']", "MPa"], ["P1006 Chamber", "P94_0_03", 0, 3, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0.1, "True", 3.1317, -2.3863, 0.0, 10.0, "[10.0, \'None\']", "MPa"], ["P1002 GOX Inlet", "P94_0_04", 0, 4, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0.1, "True", 3.1276, -2.3934, 0.0, 10.0, "[10.0, \'None\']", "MPa"], ["P1001 GOX Supply", "P94_0_05", 0, 5, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0.1, "True", 1.5622, -1.1519, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 06", "P94_0_06", 0, 6, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0, "False", 1.5629, -1.1533, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 07", "P94_0_07", 0, 7, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0, "False", 1.5633, -1.1548, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 08", "P94_0_08", 0, 8, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0, "False", 1.5622, -1.1556, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 09", "P94_0_09", 0, 9, "0x30","0x03", 0, "pressure" ,"pressure", [], 0.0,0.0, 0, "False", 1.5605, -1.142, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 10", "P94_0_10", 0, 10, "0x30","0x03", 0,"pressure" ,"pressure", [], 0.0,0.0, 0, "False", 3.1326, -2.4067, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 11", "P94_0_11", 0, 11, "0x30","0x03", 0,"pressure" ,"pressure", [], 0.0,0.0, 0, "False", 3.1354, -2.4408, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 12", "P94_0_12", 0, 12, "0x30","0x03", 0,"pressure" ,"pressure", [], 0.0,0.0, 0, "False", 3.1354, -2.4408, 0.0, 5.0, "[10.0, None]", "MPa"], ["P 13", "P94_0_13", 0, 13, "0x30","0x03", 0,"pressure" ,"pressure", [], 0.0,0.0, 0, "False", 3.1354, -2.4408, 0.0, 5.0, "[10.0, None]", "MPa"], ["T 00", "M94_1_00", 1, 0, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_00"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 01", "M94_1_01", 1, 1, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_01"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 02", "M94_1_02", 1, 2, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_02"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 03", "M94_1_03", 1, 3, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_03"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 04", "M94_1_04", 1, 4, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_04"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 05", "M94_1_05", 1, 5, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_05"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 06", "M94_1_06", 1, 6, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_06"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 07", "M94_1_07", 1, 7, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_07"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 08", "M94_1_08", 1, 8, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_08"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 09", "M94_1_09", 1, 9, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_09"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 10", "M94_1_10", 1, 10, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_10"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 11", "M94_1_11", 1, 11, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_11"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 12", "M94_1_12", 1, 12, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_12"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 13", "M94_1_13", 1, 13, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_13"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 14", "M94_1_14", 1, 14, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_14"], 1.0,0.0, 0.2, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 15", "M94_1_15", 1, 15, "0x30","0x03", 1, "temperature" ,"tempTypePT100_TypeA", ["M94_2_15"], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 373.15, "[10.0, None]", "K"], ["T 00 Comp","M94_2_00", 2, 0, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 01 Comp","M94_2_01", 2, 1, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 02 Comp","M94_2_02", 2, 2, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 03 Comp","M94_2_03", 2, 3, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 04 Comp","M94_2_04", 2, 4, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 05 Comp","M94_2_05", 2, 5, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 06 Comp","M94_2_06", 2, 6, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 07 Comp","M94_2_07", 2, 7, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 08 Comp","M94_2_08", 2, 8, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"], ["T 09 Comp","M94_2_09", 2, 9, "0x30","0x03", 1, "volt" ,"volt", [], 1.0,0.0, 0, "False", 1.0, 0.0, 0.0, 5.0, "[10.0, None]", "V"],'; $subst = "\1\2\3.\4\5\7\8.\9"; $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