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
No Match

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)(?<name>.+)" & @CRLF & _ "" & @CRLF & _ " (?<date>.+)" & @CRLF & _ " Lat=\s*(?<lat>-?\d+\.\d*)\s*Lon=\s*(?<lon>-?\d+\.\d*)" & @CRLF & _ " (?<dep>.+)" & @CRLF & _ " (?<dt>.+)" & @CRLF & _ " Moment Tensor: Expo=\d+\s*(?<cmt>.+)" & @CRLF & _ " .+" & @CRLF & _ ".+" & @CRLF & _ " (?<faultPlane>.+strike=(?<strike>-?\d+\.?\d*)\s*dip=(?<dip>-?\d+\.?\d*)\s*slip=(?<slip>-?\d+\.?\d*))" Local $sString = "010176A KERMADEC ISLANDS REGION " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/ 1 Centroid Time: 1:29:53.4 GMT" & @CRLF & _ " Lat= -29.25 Lon=-176.96" & @CRLF & _ " Depth= 47.8 Half duration= 9.4" & @CRLF & _ " Centroid time minus hypocenter time: 13.8" & @CRLF & _ " Moment Tensor: Expo=26 7.680 0.090 -7.770 1.390 4.520 -3.260 " & @CRLF & _ " Mw = 7.3 mb = 6.2 Ms = 0.0 Scalar Moment = 9.56e+26" & @CRLF & _ " Fault plane: strike=202 dip=30 slip=93" & @CRLF & _ " Fault plane: strike=18 dip=60 slip=88" & @CRLF & _ "010576A PERU " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/ 5 Centroid Time: 2:31:44.7 GMT" & @CRLF & _ " Lat= -13.42 Lon= -75.14" & @CRLF & _ " Depth= 85.4 Half duration= 1.6" & @CRLF & _ " Centroid time minus hypocenter time: 8.4" & @CRLF & _ " Moment Tensor: Expo=24 -1.780 -0.590 2.370 -1.280 1.970 -2.900 " & @CRLF & _ " Mw = 5.7 mb = 6.0 Ms = 0.0 Scalar Moment = 3.79e+24" & @CRLF & _ " Fault plane: strike=350 dip=28 slip=-60" & @CRLF & _ " Fault plane: strike=137 dip=66 slip=-105" & @CRLF & _ "010676A OFF EAST COAST OF KAMCHA" & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/ 6 Centroid Time: 21: 8:25.1 GMT" & @CRLF & _ " Lat= 51.45 Lon= 159.50" & @CRLF & _ " Depth= 15.0 Half duration= 2.8" & @CRLF & _ " Centroid time minus hypocenter time: 5.8" & @CRLF & _ " Moment Tensor: Expo=25 1.100 -0.300 -0.800 1.050 1.240 -0.560 " & @CRLF & _ " Mw = 6.1 mb = 5.7 Ms = 6.0 Scalar Moment = 1.98e+25" & @CRLF & _ " Fault plane: strike=206 dip=18 slip=78" & @CRLF & _ " Fault plane: strike=39 dip=73 slip=94" & @CRLF & _ "010976A VANUATU ISLANDS " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/ 9 Centroid Time: 23:54:40.1 GMT" & @CRLF & _ " Lat= -15.97 Lon= 167.81" & @CRLF & _ " Depth=173.7 Half duration= 3.5" & @CRLF & _ " Centroid time minus hypocenter time: 4.5" & @CRLF & _ " Moment Tensor: Expo=25 -1.700 2.290 -0.590 -2.330 -1.230 2.010 " & @CRLF & _ " Mw = 6.3 mb = 6.1 Ms = 0.0 Scalar Moment = 3.64e+25" & @CRLF & _ " Fault plane: strike=246 dip=22 slip=-86" & @CRLF & _ " Fault plane: strike=62 dip=68 slip=-91" & @CRLF & _ "011376A ICELAND REGION " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/13 Centroid Time: 13:29:24.9 GMT" & @CRLF & _ " Lat= 66.33 Lon= -16.29" & @CRLF & _ " Depth= 15.0 Half duration= 3.4" & @CRLF & _ " Centroid time minus hypocenter time: 5.4" & @CRLF & _ " Moment Tensor: Expo=25 -0.510 -2.860 3.370 0.050 -0.780 -0.860 " & @CRLF & _ " Mw = 6.3 mb = 6.0 Ms = 6.4 Scalar Moment = 3.3e+25" & @CRLF & _ " Fault plane: strike=127 dip=82 slip=173" & @CRLF & _ " Fault plane: strike=218 dip=83 slip=9" & @CRLF & _ "011476A KERMADEC ISLANDS " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/14 Centroid Time: 15:56: 7.5 GMT" & @CRLF & _ " Lat= -29.69 Lon=-177.04" & @CRLF & _ " Depth= 46.7 Half duration=20.0" & @CRLF & _ " Centroid time minus hypocenter time: 32.6" & @CRLF & _ " Moment Tensor: Expo=27 4.780 -0.490 -4.300 0.830 3.620 -1.320 " & @CRLF & _ " Mw = 7.8 mb = 6.3 Ms = 0.0 Scalar Moment = 6.02e+27" & @CRLF & _ " Fault plane: strike=200 dip=26 slip=95" & @CRLF & _ " Fault plane: strike=15 dip=64 slip=88" & @CRLF & _ "011476B KERMADEC ISLANDS REGION " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/14 Centroid Time: 16:47:44.8 GMT" & @CRLF & _ " Lat= -28.72 Lon=-176.75" & @CRLF & _ " Depth= 17.7 Half duration=20.5" & @CRLF & _ " Centroid time minus hypocenter time: 11.3" & @CRLF & _ " Moment Tensor: Expo=27 2.560 0.180 -2.740 3.580 6.770 -1.230 " & @CRLF & _ " Mw = 7.9 mb = 6.5 Ms = 8.0 Scalar Moment = 8.18e+27" & @CRLF & _ " Fault plane: strike=189 dip=11 slip=71" & @CRLF & _ " Fault plane: strike=28 dip=80 slip=93" & @CRLF & _ "011476C KERMADEC ISLANDS REGION " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/14 Centroid Time: 22:43:50.7 GMT" & @CRLF & _ " Lat= -28.61 Lon=-176.62" & @CRLF & _ " Depth= 15.0 Half duration= 3.7" & @CRLF & _ " Centroid time minus hypocenter time: 7.6" & @CRLF & _ " Moment Tensor: Expo=25 2.340 0.240 -2.580 0.620 3.710 -0.680 " & @CRLF & _ " Mw = 6.4 mb = 5.5 Ms = 6.3 Scalar Moment = 4.54e+25" & @CRLF & _ " Fault plane: strike=197 dip=17 slip=97" & @CRLF & _ " Fault plane: strike=10 dip=73 slip=88" & @CRLF & _ "011576A KERMADEC ISLANDS REGION " & @CRLF & _ "" & @CRLF & _ " Date: 1976/ 1/15 Centroid Time: 6: 6:51.9 GMT" & @CRLF & _ " Lat= -30.25 Lon=-176.63" & @CRLF & _ " Depth= 15.0 Half duration= 2.8" & @CRLF & _ " Centroid time minus hypocenter time: 5.8" & @CRLF & _ " Moment Tensor: Expo=25 1.440 0.060 -1.500 0.300 1.180 -0.460 " & @CRLF & _ " Mw = 6.1 mb = 5.3 Ms = 6.2 Scalar Moment = 1.96e+25" & @CRLF & _ " Fault plane: strike=196 dip=26 slip=91" & @CRLF & _ " Fault plane: strike=15 dip=64 slip=89" Local $sSubst = "\n%% ${name}\n% ${date}\n% ${dep}\n% ${dt}\n% ${faultPlane}\nFP = [${strike}, ${dip}, ${slip}];\nCMT = [${cmt}];\nLat = ${lat}; Lon = ${lon};\nbb(CMT, Lon, Lat, dia, 1, 'r');\n" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm