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

/
/
gmx

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 = "(?mx)(?<Loop>" & @CRLF & _ "(?<NewBlock>" & @CRLF & _ " (?:(?:" & @CRLF & _ " ^[\s]*\n" & @CRLF & _ " |" & @CRLF & _ " ^(?:(?!\/\*).)+\n" & @CRLF & _ " |" & @CRLF & _ " ^(?:(?!\/\*).)+" & @CRLF & _ " ))+" & @CRLF & _ ")?" & @CRLF & _ "(?<OldBlock>" & @CRLF & _ " (?:" & @CRLF & _ " \/\*.+\*\/" & @CRLF & _ " |" & @CRLF & _ " (?:\/\*.*\n)" & @CRLF & _ " (?:(?:" & @CRLF & _ " ^[\s]*\n" & @CRLF & _ " |" & @CRLF & _ " ^(?:(?!\*\/).)+\n" & @CRLF & _ " |" & @CRLF & _ " ^(?:(?!\*\/).)+" & @CRLF & _ " ))+" & @CRLF & _ " \*\/" & @CRLF & _ ")" & @CRLF & _ ")?" & @CRLF & _ ")+" Local $sString = " .highlight" & @CRLF & _ " {" & @CRLF & _ " background: #ffffff" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " .highlight .c," & @CRLF & _ " .highlight .cm," & @CRLF & _ " .highlight .cp," & @CRLF & _ " .highlight .c1," & @CRLF & _ " .highlight .cs" & @CRLF & _ " {" & @CRLF & _ " color: #007400;" & @CRLF & _ " }" & @CRLF & _ " /* Comment, " & @CRLF & _ " Comment.Multiline, " & @CRLF & _ " Comment.Preproc, " & @CRLF & _ " Comment.Single, " & @CRLF & _ " Comment.Special" & @CRLF & _ " */" & @CRLF & _ "" & @CRLF & _ " .highlight .k," & @CRLF & _ " .highlight .kc," & @CRLF & _ " .highlight .kd," & @CRLF & _ " .highlight .kp," & @CRLF & _ " .highlight .kr," & @CRLF & _ " .highlight .nb" & @CRLF & _ " {" & @CRLF & _ " color: #AA0D91;" & @CRLF & _ " }" & @CRLF & _ " /* Keyword," & @CRLF & _ " Keyword.Constant," & @CRLF & _ " Keyword.Declaration," & @CRLF & _ " Keyword.Pseudo," & @CRLF & _ " Name.Builtin */" & @CRLF & _ "" & @CRLF & _ " .highlight .kt" & @CRLF & _ " {" & @CRLF & _ " color: #3F6E74" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Keyword.Reserved */" & @CRLF & _ " .highlight .err" & @CRLF & _ " {" & @CRLF & _ " color: #a61717;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Error */" & @CRLF & _ " .highlight .o" & @CRLF & _ " {" & @CRLF & _ " font-weight: bold" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Operator */" & @CRLF & _ " .highlight .gd" & @CRLF & _ " {" & @CRLF & _ " color: #000000;" & @CRLF & _ " background-color: #fdd" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Deleted */" & @CRLF & _ " .highlight .gd .x" & @CRLF & _ " {" & @CRLF & _ " color: #000000;" & @CRLF & _ " background-color: #faa" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Deleted.Specific */" & @CRLF & _ " .highlight .ge" & @CRLF & _ " {" & @CRLF & _ " font-style: italic" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Emph */" & @CRLF & _ " .highlight .gr" & @CRLF & _ " {" & @CRLF & _ " color: #a00" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Error */" & @CRLF & _ " .highlight .gh" & @CRLF & _ " {" & @CRLF & _ " color: #999" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Heading */" & @CRLF & _ " .highlight .gi" & @CRLF & _ " {" & @CRLF & _ " color: #000000;" & @CRLF & _ " background-color: #dfd" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Inserted */" & @CRLF & _ " .highlight .gi .x" & @CRLF & _ " {" & @CRLF & _ " color: #000000;" & @CRLF & _ " background-color: #afa" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Inserted.Specific */" & @CRLF & _ " .highlight .go" & @CRLF & _ " {" & @CRLF & _ " color: #888" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Output */" & @CRLF & _ " .highlight .gp" & @CRLF & _ " {" & @CRLF & _ " color: #555" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Prompt */" & @CRLF & _ " .highlight .gs" & @CRLF & _ " {" & @CRLF & _ " font-weight: bold" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Strong */" & @CRLF & _ " .highlight .gu" & @CRLF & _ " {" & @CRLF & _ " color: #aaa" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Subheading */" & @CRLF & _ " .highlight .gt" & @CRLF & _ " {" & @CRLF & _ " color: #a00" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Generic.Traceback */" & @CRLF & _ " .highlight .m," & @CRLF & _ " .highlight .mf," & @CRLF & _ " .highlight .mh," & @CRLF & _ " .highlight .mi," & @CRLF & _ " .highlight .mo" & @CRLF & _ " {" & @CRLF & _ " color: #1C00CF;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.Number," & @CRLF & _ " Literal.Number.Float," & @CRLF & _ " Literal.Number.Hex," & @CRLF & _ " Literal.Number.Integer," & @CRLF & _ " Literal.Number.Oct */" & @CRLF & _ " .highlight .s" & @CRLF & _ " {" & @CRLF & _ " color: #C41A16;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String */" & @CRLF & _ " .highlight .na" & @CRLF & _ " {" & @CRLF & _ " color: teal" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Attribute */" & @CRLF & _ " .highlight .nc" & @CRLF & _ " {" & @CRLF & _ " color: #5C2699" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Class */" & @CRLF & _ " .highlight .no" & @CRLF & _ " {" & @CRLF & _ " color: teal" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Constant */" & @CRLF & _ " .highlight .ni" & @CRLF & _ " {" & @CRLF & _ " color: purple" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Entity */" & @CRLF & _ " .highlight .ne" & @CRLF & _ " {" & @CRLF & _ " color: #990000" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Exception */" & @CRLF & _ " .highlight .nn" & @CRLF & _ " {" & @CRLF & _ " color: #555" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Namespace */" & @CRLF & _ " .highlight .nt" & @CRLF & _ " {" & @CRLF & _ " color: navy" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Tag */" & @CRLF & _ " .highlight .nv," & @CRLF & _ " .highlight .nf" & @CRLF & _ " {" & @CRLF & _ " color: #3F6E74" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Variable," & @CRLF & _ " Name.Function */" & @CRLF & _ " .highlight .ow" & @CRLF & _ " {" & @CRLF & _ " font-weight: bold" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Operator.Word */" & @CRLF & _ " .highlight .w" & @CRLF & _ " {" & @CRLF & _ " color: #bbb" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Text.Whitespace */" & @CRLF & _ " .highlight .sb" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Backtick */" & @CRLF & _ " .highlight .sc" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Char */" & @CRLF & _ " .highlight .sd" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Doc */" & @CRLF & _ " .highlight .s2" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Double */" & @CRLF & _ " .highlight .se" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Escape */" & @CRLF & _ " .highlight .sh" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Heredoc */" & @CRLF & _ " .highlight .si" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Interpol */" & @CRLF & _ " .highlight .sx" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Other */" & @CRLF & _ " .highlight .sr" & @CRLF & _ " {" & @CRLF & _ " color: #009926" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Regex */" & @CRLF & _ " .highlight .s1" & @CRLF & _ " {" & @CRLF & _ " color: #d14" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Single */" & @CRLF & _ " .highlight .ss" & @CRLF & _ " {" & @CRLF & _ " color: #990073" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.String.Symbol */" & @CRLF & _ " .highlight .bp" & @CRLF & _ " {" & @CRLF & _ " color: #999" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Builtin.Pseudo */" & @CRLF & _ " .highlight .vc" & @CRLF & _ " {" & @CRLF & _ " color: teal" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Variable.Class */" & @CRLF & _ " .highlight .vg" & @CRLF & _ " {" & @CRLF & _ " color: teal" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Variable.Global */" & @CRLF & _ " .highlight .vi" & @CRLF & _ " {" & @CRLF & _ " color: teal" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Name.Variable.Instance */" & @CRLF & _ " .highlight .il" & @CRLF & _ " {" & @CRLF & _ " color: #099" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " /* Literal.Number.Integer.Long */" & @CRLF & _ " *,*:before,*:after" & @CRLF & _ " {" & @CRLF & _ " -moz-box-sizing: border-box;" & @CRLF & _ " -webkit-box-sizing: border-box;" & @CRLF & _ " box-sizing: border-box" 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