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

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)"(.+?)".+?" Local $sString = "{" & @CRLF & _ " "timelineObjects" : [ {" & @CRLF & _ " "activitySegment" : {" & @CRLF & _ " "startLocation" : {" & @CRLF & _ " "latitudeE7" : 84876125," & @CRLF & _ " "longitudeE7" : 986251728" & @CRLF & _ " }," & @CRLF & _ " "endLocation" : {" & @CRLF & _ " "latitudeE7" : 81501293," & @CRLF & _ " "longitudeE7" : 988554012" & @CRLF & _ " }," & @CRLF & _ " "duration" : {" & @CRLF & _ " "startTimestampMs" : "1577853940096"," & @CRLF & _ " "endTimestampMs" : "1577867160036"" & @CRLF & _ " }," & @CRLF & _ " "distance" : 45275," & @CRLF & _ " "activityType" : "IN_PASSENGER_VEHICLE"," & @CRLF & _ " "confidence" : "HIGH"," & @CRLF & _ " "activities" : [ {" & @CRLF & _ " "activityType" : "IN_PASSENGER_VEHICLE"," & @CRLF & _ " "probability" : 78.98348569869995" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "STILL"," & @CRLF & _ " "probability" : 13.971047103404999" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "MOTORCYCLING"," & @CRLF & _ " "probability" : 3.0464861541986465" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "WALKING"," & @CRLF & _ " "probability" : 2.5266656652092934" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_FERRY"," & @CRLF & _ " "probability" : 0.7077858783304691" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "CYCLING"," & @CRLF & _ " "probability" : 0.23177380207926035" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "FLYING"," & @CRLF & _ " "probability" : 0.2262754598632455" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_BUS"," & @CRLF & _ " "probability" : 0.1849415129981935" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "RUNNING"," & @CRLF & _ " "probability" : 0.0680008321069181" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "SAILING"," & @CRLF & _ " "probability" : 0.029427077970467508" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "SKIING"," & @CRLF & _ " "probability" : 0.015666104445699602" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_TRAIN"," & @CRLF & _ " "probability" : 0.006996936281211674" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_SUBWAY"," & @CRLF & _ " "probability" : 0.0010493132322153542" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_TRAM"," & @CRLF & _ " "probability" : 3.152051021970692E-4" & @CRLF & _ " }, {" & @CRLF & _ " "activityType" : "IN_VEHICLE"," & @CRLF & _ " "probability" : 8.468594501209736E-5" & @CRLF & _ " } ]," & @CRLF & _ " "simplifiedRawPath" : {" & @CRLF & _ " "points" : [ {" & @CRLF & _ " "latE7" : 81042775," & @CRLF & _ " "lngE7" : 989657755," & @CRLF & _ " "timestampMs" : "1577867101472"," & @CRLF & _ " "accuracyMeters" : 122" & @CRLF & _ " } ]" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }, {" & @CRLF & _ " "placeVisit" : {" & @CRLF & _ " "location" : {" & @CRLF & _ " "latitudeE7" : 81037885," & @CRLF & _ " "longitudeE7" : 989663263," & @CRLF & _ " "placeId" : "ChIJrX3SBcuTUTAR4r4hEgpoSvA"," & @CRLF & _ " "address" : "313 หมู่ 12 อำเภอ เมือง\nตำบล กระบี่น้อย อำเภอเมืองกระบี่\nกระบี่ 81000\nThailand"," & @CRLF & _ " "name" : "สำนักงานทางหลวงที่ 17"," & @CRLF & _ " "sourceInfo" : {" & @CRLF & _ " "deviceTag" : -1189270403" & @CRLF & _ " }," & @CRLF & _ " "locationConfidence" : 63.438793" & @CRLF & _ " }," & @CRLF & _ " "duration" : {" & @CRLF & _ " "startTimestampMs" : "1577867160036"," & @CRLF & _ " "endTimestampMs" : "1577873822494"" & @CRLF & _ " }," & @CRLF & _ " "placeConfidence" : "MEDIUM_CONFIDENCE"," & @CRLF & _ " "centerLatE7" : 81042540," & @CRLF & _ " "centerLngE7" : 989657723," & @CRLF & _ " "visitConfidence" : 91," & @CRLF & _ " "otherCandidateLocations" : [ {" & @CRLF & _ " "latitudeE7" : 81035660," & @CRLF & _ " "longitudeE7" : 989642884," & @CRLF & _ " "placeId" : "ChIJmfJgxcuTUTAR-VQR_9hOeGk"," & @CRLF & _ " "locationConfidence" : 21.532362" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " } ]" & @CRLF & _ "}" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm