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)^\s*(\d{1,3})\s+([a-zA-z0-9-_]+\s?[a-zA-z0-9-_]+)\s+(0x[a-zA-Z0-9]{4})\s+(\d{3})\s+(\d{3})\s+(\d+)\s+([a-zA-z0-9-_]+\s?\w+)\s+(\w+)\s+-\s+(\d+)" Local $sString = "ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE" & @CRLF & _ " 5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0" & @CRLF & _ " 9 Power_On_Hours 0x0032 096 096 000 Old_age Always - 19033" & @CRLF & _ " 12 Power_Cycle_Count 0x0032 099 099 000 Old_age Always - 54" & @CRLF & _ "170 Unused_Rsvd_Blk_Ct_Chip 0x0032 100 100 010 Old_age Always - 0" & @CRLF & _ "171 Program_Fail_Count_Chip 0x0032 100 100 010 Old_age Always - 0" & @CRLF & _ "172 Erase_Fail_Count_Chip 0x0032 100 100 010 Old_age Always - 0" & @CRLF & _ "173 Wear_Leveling_Count 0x0033 090 090 005 Pre-fail Always - 121" & @CRLF & _ "174 Unexpect_Power_Loss_Ct 0x0032 099 099 000 Old_age Always - 12" & @CRLF & _ "178 Used_Rsvd_Blk_Cnt_Chip 0x0013 100 100 010 Pre-fail Always - 0" & @CRLF & _ "180 Unused_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 1618" & @CRLF & _ "184 End-to-End_Error 0x0033 100 100 097 Pre-fail Always - 0" & @CRLF & _ "187 Uncorrectable_Error_Cnt 0x0032 100 100 000 Old_age Always - 0" & @CRLF & _ "194 Temperature_Celsius 0x0032 059 055 000 Old_age Always - 41" & @CRLF & _ "199 CRC_Error_Count 0x003e 099 099 000 Old_age Always - 21" & @CRLF & _ "233 Media_Wearout_Indicator 0x0013 090 090 000 Pre-fail Always - 15085512" & @CRLF & _ "241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 19103" & @CRLF & _ "242 Total_LBAs_Read 0x0032 099 099 000 Old_age Always - 23403" & @CRLF & _ "249 NAND_Writes_1GiB 0x0032 099 099 000 Old_age Always - 61952" 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