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

/
/
x

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 = "(?x)(?(DEFINE)" & @CRLF & _ "# JSON does not need backtracking if it's valid" & @CRLF & _ "# so everything is atomic to prevent backtracking" & @CRLF & _ "# regex is built per https://tools.ietf.org/html/rfc8259" & @CRLF & _ "(?<json>(?>\s*(?&object)\s*|\s*(?&array)\s*))" & @CRLF & _ "(?<object>(?>\{\s*(?>(?&member)(?>\s*,\s*(?&member))*)?\s*\}))" & @CRLF & _ "(?<member>(?>(?&string)\s*:\s*(?&value)))" & @CRLF & _ "(?<array>(?>\[\s*(?>(?&value)(?>\s*,\s*(?&value))*)?\s*\]))" & @CRLF & _ "(?<value>(?>)false|null|true|(?&object)|(?&array)|(?&number)|(?&string))" & @CRLF & _ "(?<number>(?>-?(?>0|[1-9][0-9]*)(?>\.[0-9]+)?(?>[eE][-+]?[0-9]+)?))" & @CRLF & _ "(?<string>(?>"(?>\\(?>["\\\/bfnrt]|u[a-fA-F0-9]{4})|[^"\\\0-\x1F\x7F]+)*"))" & @CRLF & _ ")" & @CRLF & _ "\A(?&json)\z" & @CRLF & _ "" Local $sString = "[" & @CRLF & _ " "JSON Test Pattern pass1"," & @CRLF & _ " {"object with 1 member":["array with 1 element"]}," & @CRLF & _ " {}," & @CRLF & _ " []," & @CRLF & _ " -42," & @CRLF & _ " true," & @CRLF & _ " false," & @CRLF & _ " null," & @CRLF & _ " {" & @CRLF & _ " "integer": 1234567890," & @CRLF & _ " "real": -9876.543210," & @CRLF & _ " "e": 0.123456789e-12," & @CRLF & _ " "E": 1.234567890E+34," & @CRLF & _ " "": 23456789012E66," & @CRLF & _ " "zero": 0," & @CRLF & _ " "one": 1," & @CRLF & _ " "space": " "," & @CRLF & _ " "quote": "\""," & @CRLF & _ " "backslash": "\\"," & @CRLF & _ " "controls": "\b\f\n\r\t"," & @CRLF & _ " "slash": "/ & \/"," & @CRLF & _ " "alpha": "abcdefghijklmnopqrstuvwyz"," & @CRLF & _ " "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ"," & @CRLF & _ " "digit": "0123456789"," & @CRLF & _ " "0123456789": "digit"," & @CRLF & _ " "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?"," & @CRLF & _ " "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"," & @CRLF & _ " "true": true," & @CRLF & _ " "false": false," & @CRLF & _ " "null": null," & @CRLF & _ " "array":[ ]," & @CRLF & _ " "object":{ }," & @CRLF & _ " "address": "50 St. James Street"," & @CRLF & _ " "url": "http://www.JSON.org/"," & @CRLF & _ " "comment": "// /* <!-- --"," & @CRLF & _ " "# -- --> */": " "," & @CRLF & _ " " s p a c e d " :[1,2 , 3" & @CRLF & _ "" & @CRLF & _ "," & @CRLF & _ "" & @CRLF & _ "4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7]," & @CRLF & _ " "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}"," & @CRLF & _ " "quotes": "&#34; \u0022 %22 0x22 034 &#x22;"," & @CRLF & _ " "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"" & @CRLF & _ ": "A key can be any string"" & @CRLF & _ " }," & @CRLF & _ " 0.5 ,98.6" & @CRLF & _ "," & @CRLF & _ "99.44" & @CRLF & _ "," & @CRLF & _ "" & @CRLF & _ "1066," & @CRLF & _ "1e1," & @CRLF & _ "0.1e1," & @CRLF & _ "1e-1," & @CRLF & _ "1e00,2e+00,2e-00" & @CRLF & _ ","rosebud"]" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH) ; 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