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
No Match

/
/

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 = "_gpfErrorDeclare\("([a-zA-Z\\]+)", {\n((?:.*\n)*)\s*}\)" Local $sString = "/**" & @CRLF & _ " * @file Error base class" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ "/*#ifndef(UMD)*/" & @CRLF & _ ""use strict";" & @CRLF & _ "/*global _gpfExtend*/ // gpf.extend" & @CRLF & _ "/*global _gpfIgnore*/ // Helper to remove unused parameter warning" & @CRLF & _ "/*global _gpfObjectForEach*/ // Similar to [].forEach but for objects" & @CRLF & _ "/*global _gpfStringCapitalize*/ // Capitalize the string" & @CRLF & _ "/*global _gpfStringReplaceEx*/ // String replacement using dictionary map" & @CRLF & _ "/*exported _gpfErrorDeclare*/ // Declare new gpf.Error names" & @CRLF & _ "/*#endif*/" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * GPF Error class" & @CRLF & _ " *" & @CRLF & _ " * @constructor" & @CRLF & _ " * @alias gpf.Error" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ "var _GpfError = gpf.Error = function () {};" & @CRLF & _ "" & @CRLF & _ "_GpfError.prototype = new Error();" & @CRLF & _ "_gpfExtend(_GpfError.prototype, /** @lends gpf.Error.prototype */ {" & @CRLF & _ "" & @CRLF & _ " constructor: _GpfError," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * Error code" & @CRLF & _ " *" & @CRLF & _ " * @readonly" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " code: 0," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * Error name" & @CRLF & _ " *" & @CRLF & _ " * @readonly" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " name: "Error"," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * Error message" & @CRLF & _ " *" & @CRLF & _ " * @readonly" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " message: ""," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * Build message by substituting context variables" & @CRLF & _ " *" & @CRLF & _ " * @param {Object} context Dictionary of named keys" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " _buildMessage: function (context) {" & @CRLF & _ " var replacements;" & @CRLF & _ " if (context) {" & @CRLF & _ " replacements = {};" & @CRLF & _ " _gpfObjectForEach(context, function (value, key) {" & @CRLF & _ " replacements["{" + key + "}"] = value.toString();" & @CRLF & _ " });" & @CRLF & _ " this.message = _gpfStringReplaceEx(this.message, replacements);" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "function _gpfErrorFactory (code, name, message) {" & @CRLF & _ " function NewErrorClass (context) {" & @CRLF & _ " this._buildMessage(context);" & @CRLF & _ " }" & @CRLF & _ " NewErrorClass.prototype = new _GpfError();" & @CRLF & _ " _gpfExtend(NewErrorClass.prototype, {" & @CRLF & _ " code: code," & @CRLF & _ " name: name," & @CRLF & _ " message: message" & @CRLF & _ " });" & @CRLF & _ " // constructor can't be enumerated with wscript" & @CRLF & _ " NewErrorClass.prototype.constructor = NewErrorClass;" & @CRLF & _ " _GpfError[_gpfStringCapitalize(name)] = NewErrorClass;" & @CRLF & _ " return function (context) {" & @CRLF & _ " throw new NewErrorClass(context);" & @CRLF & _ " };" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * Generates an error class" & @CRLF & _ " *" & @CRLF & _ " * @param {Number} code Error code" & @CRLF & _ " * @param {String} name Error name" & @CRLF & _ " * @param {String} message Error message" & @CRLF & _ " * @return {Function} New error class" & @CRLF & _ " * @gpf:closure" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ "function _gpfGenenerateErrorFunction (code, name, message) {" & @CRLF & _ " var result = _gpfErrorFactory(code, name, message);" & @CRLF & _ " result.CODE = code;" & @CRLF & _ " result.NAME = name;" & @CRLF & _ " result.MESSAGE = message;" & @CRLF & _ " return result;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "// Last allocated error code" & @CRLF & _ "var _gpfLastErrorCode = 0;" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " * Declare error messages." & @CRLF & _ " * Each source declares its own errors." & @CRLF & _ " *" & @CRLF & _ " * @param {String} source Source name" & @CRLF & _ " * @param {Object} dictionary Dictionary of error name to message" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ "function _gpfErrorDeclare (source, dictionary) {" & @CRLF & _ " _gpfIgnore(source);" & @CRLF & _ " _gpfObjectForEach(dictionary, function (message, name) {" & @CRLF & _ " var code = ++_gpfLastErrorCode;" & @CRLF & _ " gpf.Error["CODE_" + name.toUpperCase()] = code;" & @CRLF & _ " gpf.Error[name] = _gpfGenenerateErrorFunction(code, name, message);" & @CRLF & _ " });" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "_gpfErrorDeclare("error", {" & @CRLF & _ " /**" & @CRLF & _ " * ### Summary" & @CRLF & _ " *" & @CRLF & _ " * Method or function is not implemented" & @CRLF & _ " *" & @CRLF & _ " * ### Description" & @CRLF & _ " *" & @CRLF & _ " * This error is used to flag methods or functions that are not yet implemented." & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " notImplemented:" & @CRLF & _ " "Not implemented"," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * ### Summary" & @CRLF & _ " *" & @CRLF & _ " * Method is abstract" & @CRLF & _ " *" & @CRLF & _ " * ### Description" & @CRLF & _ " *" & @CRLF & _ " * This error is used to implement abstract methods. Mostly used for interfaces." & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " abstractMethod:" & @CRLF & _ " "Abstract method"," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * ### Summary" & @CRLF & _ " *" & @CRLF & _ " * An assertion failed" & @CRLF & _ " *" & @CRLF & _ " * ### Description" & @CRLF & _ " *" & @CRLF & _ " * This error is triggered when an assertion fails" & @CRLF & _ " *" & @CRLF & _ " * @see {@link gpf.assert}" & @CRLF & _ " * @see {@link gpf.asserts}" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " assertionFailed:" & @CRLF & _ " "Assertion failed: {message}"," & @CRLF & _ "" & @CRLF & _ " /**" & @CRLF & _ " * ### Summary" & @CRLF & _ " *" & @CRLF & _ " * Method or function was called with an invalid parameter" & @CRLF & _ " *" & @CRLF & _ " * ### Description" & @CRLF & _ " *" & @CRLF & _ " * This error is used when a parameter is invalid" & @CRLF & _ " * @since 0.1.5" & @CRLF & _ " */" & @CRLF & _ " invalidParameter:" & @CRLF & _ " "Invalid parameter"" & @CRLF & _ "});" & @CRLF & _ "" 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