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"
"
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)[^\d\.](((01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3}[\. ]?[\dX]{2}[\. \-]?[\dX]{2}|(01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3}[\. ]?[\dX]{2}|(01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)[\. ]?[\dX]{3})(?![\d\.X]))|([^\d\.](01|03|07|11|13|17|19|21|23|25|27|29|31|33|35|37|39|43|45|47|49|53|55|59|61|65|67|71|73|75|77|79|81|83|85|87|91|93|95|97|99)(?![\d\.X]|( ?%)))" Local $sString = " HS codes: 271012 (Petroleum oils and oils obtained from bituminous minerals, other than crude; preparations not elsewhere specified or included, containing by weight 70 % or more of petroleum oils or of oils obtained from bituminous minerals, these oils being the basic constituents of the preparations; 33.234-33.237 waste oils : Petroleum oils and oils obtained from bituminous minerals (other than crude) and preparations not elsewhere specified or included, containing by weight 70 % or more of petroleum oils or of oils obtained from bituminous minerals, these oils being the basic constituents of the preparations, other than those containinandandandg biodiesel and other than waste oils : Light oils and preparations), 271019 (Petroleum oils and oils obtained from bituminous minerals, other than crude; preparations not elsewhere specified or included, containing by weight 70 % or more of petroleum oils or of oils obtained from bituminous minerals, these oils being the basic constituents of the " & @CRLF & _ "preparations; waste oils : Petroleum oils and oils obtained from bituminous minerals (other than crude) and preparations not elsewhere specified or included, containing by weight 70 % or more of petroleum oils or of oils obtained from bituminous minerals, these oils being the basic constituents of the preparations, other than those containing biodiesel and other than waste oils : Other);" & @CRLF & _ "ICS codes: 03.120 (Quality), 13.020 (Environmental protection), 75.160 (Fuels);HS 1234 2134 5325 ösadlkjföasfas " & @CRLF & _ "HS: 8418 694X" & @CRLF & _ "HS: 8415 10XX" & @CRLF & _ "HS: 8418 694X" & @CRLF & _ "HS: 8415 10XX" & @CRLF & _ "HS 8418 101X, 8418 21XX" & @CRLF & _ "ICS codes: 23.120 (Ventilators. Fans. Air-conditioners), 27.200 (Refrigerating technology), 71.100.45 (Refrigerants and antifreezes);ICS codes: 23.120 (Ventilators. Fans. Air-conditioners), 27.200 (Refrigerating technology), 71.100.45 (Refrigerants and antifreezes); " & @CRLF & _ "ICS codes: 43.040.65 (Glazing and wiper systems)" & @CRLF & _ "HS codes:" & @CRLF & _ "39.26.90.90.90" & @CRLF & _ "70.07.11.00.00" & @CRLF & _ "70.07.21.00.00" & @CRLF & _ "234" & @CRLF & _ "87.08.29.50.00" & @CRLF & _ "ICS-Codes:" & @CRLF & _ "83.160 (Tyres)" & @CRLF & _ "(HS 4011)." & @CRLF & _ "Electrical and electronic equipment (EEE). More detail on product coverage can be found in Restriction of the Use of Certain Hazardous Substances in Electrical and Electro 23XX n ic Equipment Regulations 2012 (SI 2012/3032) (https://www.legislation.gov.uk/uksi/2012/3032/made). HS code 9018 for medical devices. Electronic Components in general (ICS 31.020); Electronic components in general (ICS 31.020)" & @CRLF & _ "Air emission sources; Quality (ICS code(s): 03.120); Environmental protection (ICS code(s): 13.020); Air quality (ICS code(s): 13.040); Test conditions and procedures in general (ICS code(s): 19.020)" & @CRLF & _ "Passenger car (including New Energy Vehicle) (HS code(s): 8703); (ICS code(s): 43.060; 43.080.01; 43.100; 75.160)" & @CRLF & _ "ICS codes: 29, 33, 97, 29 , 33, 97;" & @CRLF & _ "" & @CRLF & _ "75.16X" & @CRLF & _ "" & @CRLF & _ "13" & @CRLF & _ "13.123.34-34" 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