Regular Expressions 101

Save & Share

  • Regex Version: ver. 27
  • 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
No Match

/
/
gu

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 = "(?u)(?<=^|[\n;](?:[\t ]*(?:\w+ )?)?)(?:(?:const\s*|let\s*|var\s*)?(?<imports>(?:[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*)|(?<=const\s*|let\s*|var\s*)(?:[\w\t\n\r "$'*,./:{}-]+?))\s*=\s*)?(?:await\s+)?(?<expression>import\((?<specifier>[\S\t\n\r]+?)(?:,\s*(?<options>\{\s*assert:.+[\w\t\n\r "':]+\}\s*\}))?\))" Local $sString = "await import(foo)" & @CRLF & _ "await import('foo')" & @CRLF & _ "const foo = await import('bar')" & @CRLF & _ "const foo = await import(bar)" & @CRLF & _ "const promise = import('./foo');" & @CRLF & _ "const { readPackage } = await import('read-pkg')" & @CRLF & _ "const { " & @CRLF & _ " readPackageUp," & @CRLF & _ " readPackageUpSync" & @CRLF & _ "} = await import('read-pkg');" & @CRLF & _ "const {" & @CRLF & _ " addFive," & @CRLF & _ " addFour," & @CRLF & _ " addThree," & @CRLF & _ " addTwo," & @CRLF & _ " squareFive," & @CRLF & _ " squareFour," & @CRLF & _ " squareThree," & @CRLF & _ " squareTwo" & @CRLF & _ "} = await import('./lib')" & @CRLF & _ "await import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _ "var g;const{foo}=await import('bar');const{ foo }=await import('bar')" & @CRLF & _ "import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _ "import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _ "" & @CRLF & _ "import('buzz').catch(() => ({}))" & @CRLF & _ "" & @CRLF & _ "const foo = "./utils.mjs"; await import(foo)" & @CRLF & _ "" & @CRLF & _ "const { default: barData } =" & @CRLF & _ " await import('./bar.json');" & @CRLF & _ "" & @CRLF & _ "const { default: barData } =" & @CRLF & _ " await import('./bar.json', { assert: { type: 'json' } });" & @CRLF & _ "" & @CRLF & _ "(async () => {" & @CRLF & _ " if (somethingIsTrue) {" & @CRLF & _ " // import module for side effects" & @CRLF & _ " await import("/modules/my-module.js");" & @CRLF & _ " }" & @CRLF & _ "})();" & @CRLF & _ "" & @CRLF & _ "await import('__tests__/report.json', { " & @CRLF & _ " assert: { type: 'json' }" & @CRLF & _ "})" & @CRLF & _ "" & @CRLF & _ " await import('__tests__/report.json', {" & @CRLF & _ " assert: { type: 'json' }" & @CRLF & _ " })" & @CRLF & _ "" & @CRLF & _ "(async () => {" & @CRLF & _ " if (somethingIsTrue) {" & @CRLF & _ " const {" & @CRLF & _ " default: myDefault," & @CRLF & _ " foo," & @CRLF & _ " bar," & @CRLF & _ " } = await import("/modules/my-module.js");" & @CRLF & _ " }" & @CRLF & _ "})();" & @CRLF & _ "" & @CRLF & _ "const main = document.querySelector("main");" & @CRLF & _ "for (const link of document.querySelectorAll("nav > a")) {" & @CRLF & _ " link.addEventListener("click", (e) => {" & @CRLF & _ " e.preventDefault();" & @CRLF & _ "" & @CRLF & _ " import("/modules/my-module.js")" & @CRLF & _ " .then((module) => {" & @CRLF & _ " module.loadPageInto(main);" & @CRLF & _ " })" & @CRLF & _ " .then((module) => {" & @CRLF & _ " module.loadPageInto(main);" & @CRLF & _ " })" & @CRLF & _ " .then((module) => {" & @CRLF & _ " module.loadPageInto(main);" & @CRLF & _ " })" & @CRLF & _ " .catch((err) => {" & @CRLF & _ " main.textContent = err.message;" & @CRLF & _ " });" & @CRLF & _ " });" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "let myModule;" & @CRLF & _ "" & @CRLF & _ "if (typeof window === "undefined") {" & @CRLF & _ " myModule = await import("module-used-on-server");" & @CRLF & _ "} else {" & @CRLF & _ " myModule = await import("module-used-in-browser");" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "Promise.all(" & @CRLF & _ " Array.from({ length: 10 }).map((_, index) =>" & @CRLF & _ " import(`/modules/module-${index}.js`)" & @CRLF & _ " )" & @CRLF & _ ").then((modules) => modules.forEach((module) => module.load()));" & @CRLF & _ "" & @CRLF & _ " Array.from({ length: 10 }).map((_, index) => {" & @CRLF & _ " return import(`/modules/module-${index}.js`)" & @CRLF & _ " })" & @CRLF & _ "" & @CRLF & _ "'await import("foo")'" & @CRLF & _ ""await import('foo')"" & @CRLF & _ "" & @CRLF & _ "// await import('foo')" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * @example" & @CRLF & _ " * const { readPackageUp } = await import('read-pkg')" & @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