Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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)(?x) # free-spacing mode" & @CRLF & _ "(?(DEFINE)" & @CRLF & _ " # Within this DEFINE block, we'll define many subroutines" & @CRLF & _ " # They build on each other like lego until we can define" & @CRLF & _ " # a "big number"" & @CRLF & _ "" & @CRLF & _ " (?<one_to_9> " & @CRLF & _ " # The basic regex:" & @CRLF & _ " # one|two|three|four|five|six|seven|eight|nine" & @CRLF & _ " # We'll use an optimized version:" & @CRLF & _ " # Option 1: four|eight|(?:fiv|(?:ni|o)n)e|t(?:wo|hree)|" & @CRLF & _ " # s(?:ix|even)" & @CRLF & _ " # Option 2:" & @CRLF & _ " (?:f(?:ive|our)|s(?:even|ix)|t(?:hree|wo)|(?:ni|o)ne|eight)" & @CRLF & _ " ) # end one_to_9 definition" & @CRLF & _ "" & @CRLF & _ " (?<ten_to_19> " & @CRLF & _ " # The basic regex:" & @CRLF & _ " # ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|" & @CRLF & _ " # eighteen|nineteen" & @CRLF & _ " # We'll use an optimized version:" & @CRLF & _ " # Option 1: twelve|(?:(?:elev|t)e|(?:fif|eigh|nine|(?:thi|fou)r|" & @CRLF & _ " # s(?:ix|even))tee)n" & @CRLF & _ " # Option 2:" & @CRLF & _ " (?:(?:(?:s(?:even|ix)|f(?:our|if)|nine)te|e(?:ighte|lev))en|" & @CRLF & _ " t(?:(?:hirte)?en|welve)) " & @CRLF & _ " ) # end ten_to_19 definition" & @CRLF & _ "" & @CRLF & _ " (?<two_digit_prefix>" & @CRLF & _ " # The basic regex:" & @CRLF & _ " # twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety" & @CRLF & _ " # We'll use an optimized version:" & @CRLF & _ " # Option 1: (?:fif|six|eigh|nine|(?:tw|sev)en|(?:thi|fo)r)ty" & @CRLF & _ " # Option 2:" & @CRLF & _ " (?:s(?:even|ix)|t(?:hir|wen)|f(?:if|or)|eigh|nine)ty" & @CRLF & _ " ) # end two_digit_prefix definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_99>" & @CRLF & _ " (?&two_digit_prefix)(?:[- ](?&one_to_9))?|(?&ten_to_19)|" & @CRLF & _ " (?&one_to_9)" & @CRLF & _ " ) # end one_to_99 definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_999>" & @CRLF & _ " (?&one_to_9)[ ]hundred(?:[ ](?:and[ ])?(?&one_to_99))?|" & @CRLF & _ " (?&one_to_99)" & @CRLF & _ " ) # end one_to_999 definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_999_999>" & @CRLF & _ " (?&one_to_999)[ ]thousand(?:[ ](?&one_to_999))?|" & @CRLF & _ " (?&one_to_999)" & @CRLF & _ " ) # end one_to_999_999 definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_999_999_999>" & @CRLF & _ " (?&one_to_999)[ ]million(?:[ ](?&one_to_999_999))?|" & @CRLF & _ " (?&one_to_999_999)" & @CRLF & _ " ) # end one_to_999_999_999 definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_999_999_999_999>" & @CRLF & _ " (?&one_to_999)[ ]billion(?:[ ](?&one_to_999_999_999))?|" & @CRLF & _ " (?&one_to_999_999_999)" & @CRLF & _ " ) # end one_to_999_999_999_999 definition" & @CRLF & _ "" & @CRLF & _ " (?<one_to_999_999_999_999_999>" & @CRLF & _ " (?&one_to_999)[ ]trillion(?:[ ](?&one_to_999_999_999_999))?|" & @CRLF & _ " (?&one_to_999_999_999_999)" & @CRLF & _ " ) # end one_to_999_999_999_999_999 definition" & @CRLF & _ "" & @CRLF & _ " (?<bignumber>" & @CRLF & _ " zero|(?&one_to_999_999_999_999_999)" & @CRLF & _ " ) # end bignumber definition" & @CRLF & _ "" & @CRLF & _ " (?<zero_to_9>" & @CRLF & _ " (?&one_to_9)|zero" & @CRLF & _ " ) # end zero to 9 definition" & @CRLF & _ "" & @CRLF & _ " (?<decimals>" & @CRLF & _ " point(?:[ ](?&zero_to_9))+" & @CRLF & _ " ) # end decimals definition" & @CRLF & _ " " & @CRLF & _ ") # End DEFINE" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "####### The Regex Matching Starts Here ########" & @CRLF & _ "^(?&bignumber)(?:[ ](?&decimals))?$" & @CRLF & _ "" & @CRLF & _ "### Other examples of groups we could match ###" & @CRLF & _ "#(?&bignumber)" & @CRLF & _ "# (?&one_to_99)" & @CRLF & _ "# (?&one_to_999)" & @CRLF & _ "# (?&one_to_999_999)" & @CRLF & _ "# (?&one_to_999_999_999)" & @CRLF & _ "# (?&one_to_999_999_999_999)" & @CRLF & _ "# (?&one_to_999_999_999_999_999)" Local $sString = "one trillion" & @CRLF & _ "seven hundred twenty two" & @CRLF & _ "7even" & @CRLF & _ "zero point nine five" & @CRLF & _ "nine hundred ninety nine thousand two hundred thirteen" 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