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

r"
"
gs

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 = "(?s) SG_ (\w+) : (\d+)\|(\d+)@[01][+-] \(([0-9E\-\+\.]*),([0-9E\-\+\.]*)\) \[[0-9E\-\+\.]*\|[0-9E\-\+\.]*\] "([^"]*)" Vector__XXX" Local $sString = "VERSION """ & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "NS_ : " & @CRLF & _ " NS_DESC_" & @CRLF & _ " CM_" & @CRLF & _ " BA_DEF_" & @CRLF & _ " BA_" & @CRLF & _ " VAL_" & @CRLF & _ " CAT_DEF_" & @CRLF & _ " CAT_" & @CRLF & _ " FILTER" & @CRLF & _ " BA_DEF_DEF_" & @CRLF & _ " EV_DATA_" & @CRLF & _ " ENVVAR_DATA_" & @CRLF & _ " SGTYPE_" & @CRLF & _ " SGTYPE_VAL_" & @CRLF & _ " BA_DEF_SGTYPE_" & @CRLF & _ " BA_SGTYPE_" & @CRLF & _ " SIG_TYPE_REF_" & @CRLF & _ " VAL_TABLE_" & @CRLF & _ " SIG_GROUP_" & @CRLF & _ " SIG_VALTYPE_" & @CRLF & _ " SIGTYPE_VALTYPE_" & @CRLF & _ " BO_TX_BU_" & @CRLF & _ " BA_DEF_REL_" & @CRLF & _ " BA_REL_" & @CRLF & _ " BA_DEF_DEF_REL_" & @CRLF & _ " BU_SG_REL_" & @CRLF & _ " BU_EV_REL_" & @CRLF & _ " BU_BO_REL_" & @CRLF & _ "" & @CRLF & _ "BS_:" & @CRLF & _ "" & @CRLF & _ "BU_:" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "BO_ 777 VBOX_9: 8 Vector__XXX" & @CRLF & _ " SG_ Longitude_48bit : 7|48@0- (1E-07,0) [0|0] "minutes" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 776 VBOX_8: 8 Vector__XXX" & @CRLF & _ " SG_ Latitude_48bit : 7|48@0- (1E-07,0) [0|0] "minutes" Vector__XXX" & @CRLF & _ " SG_ Kalman_filter_status : 56|1@0+ (1,0) [0|1] "" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 774 VBOX_6: 8 Vector__XXX" & @CRLF & _ " SG_ Vel_Quality : 7|16@0- (0.01,0) [0|0] "km/h" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 773 VBOX_5: 8 Vector__XXX" & @CRLF & _ " SG_ Trig_Vel_Mph : 55|16@0+ (0.0115078,0) [0|754.163673] "Mph" Vector__XXX" & @CRLF & _ " SG_ Trig_Vel_Kmh : 55|16@0+ (0.01852,0) [0|1213.7082] "Km/h" Vector__XXX" & @CRLF & _ " SG_ Trig_time : 39|16@0+ (0.01,0) [0|655.35] "Secs" Vector__XXX" & @CRLF & _ " SG_ Distance : 7|32@0+ (7.8125E-05,0) [0|335544] "Metres" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 772 VBOX_4: 8 Vector__XXX" & @CRLF & _ " SG_ Lateral_acceleration : 55|16@0- (0.01,0) [-327.68|327.67] "G" Vector__XXX" & @CRLF & _ " SG_ Longitudinal_acceleration : 39|16@0- (0.01,0) [-327.68|327.67] "G" Vector__XXX" & @CRLF & _ " SG_ Trig_Dist : 7|32@0+ (7.8125E-05,0) [0|335544] "Metres" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 771 VBOX_3: 8 Vector__XXX" & @CRLF & _ " SG_ DGPS : 61|1@0+ (1,0) [0|0] "On" Vector__XXX" & @CRLF & _ " SG_ Brake_trigger : 60|1@0+ (1,0) [0|0] "On" Vector__XXX" & @CRLF & _ " SG_ Vertical_Velocity : 31|16@0- (0.01,0) [0|655.36] "m/s" Vector__XXX" & @CRLF & _ " SG_ Altitude_WGS84 : 7|24@0- (0.01,0) [0|42949700] "metres" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 770 VBOX_2: 8 Vector__XXX" & @CRLF & _ " SG_ Velocity_Mph : 39|16@0+ (0.0115078,0) [0|754.163673] "Mph" Vector__XXX" & @CRLF & _ " SG_ Heading : 55|16@0+ (0.01,0) [0|359.99] "Degrees" Vector__XXX" & @CRLF & _ " SG_ Velocity_Kmh : 39|16@0+ (0.01852,0) [0|1213.7082] "Km/h" Vector__XXX" & @CRLF & _ " SG_ Longitude : 7|32@0- (1E-05,0) [-21474.83648|21474.83647] "Minutes" Vector__XXX" & @CRLF & _ "" & @CRLF & _ "BO_ 769 VBOX_1: 8 Vector__XXX" & @CRLF & _ " SG_ Latitude : 39|32@0- (1E-05,0) [-21474.83648|21474.83647] "Minutes" Vector__XXX" & @CRLF & _ " SG_ Time_Since_Midnight : 15|24@0+ (0.01,0) [0|0] "Seconds" Vector__XXX" & @CRLF & _ " SG_ Sats : 7|8@0+ (1,0) [0|12] "Sats" Vector__XXX" & @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