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

@
@
xJm

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 = "(?xJm)#OxJm)" & @CRLF & _ " (?(DEFINE)" & @CRLF & _ " # Tokens that act as one unit." & @CRLF & _ " (?<rem>" & @CRLF & _ " /\* (?:[^*]++|\*(?!/))*+ \*/ # block comment" & @CRLF & _ " | //[^\r\n]++(?:\r?+\n?+|$) # line comment" & @CRLF & _ " )" & @CRLF & _ " (?<squote> '(?:[^'\\]++|\\.)*+')" & @CRLF & _ " (?<dquote> "(?:[^"\\]++|\\.)*+")" & @CRLF & _ " (?<rquote>R "(?<delim>[^(]*+)\((?:[^)]++|\)(?!\k{delim}"))*+\)\k{delim}")" & @CRLF & _ " (?<string_literal>" & @CRLF & _ " (?<string_literal_helper>(?&squote)|(?&dquote)|(?&rquote))" & @CRLF & _ " (?:\s*+(?&string_literal_helper))*+" & @CRLF & _ " )" & @CRLF & _ " (?<int_literal>[-+]?+\s*+" & @CRLF & _ " (?:" & @CRLF & _ " 0[xX](?<hex>[a-fA-F\d]++ (?:'(?&hex))?+)" & @CRLF & _ " | 0[bB](?<bin> [01]++ (?:'(?&bin))?+)" & @CRLF & _ " | 0 (?<oct> [0-7]++ (?:'(?&oct))?+)" & @CRLF & _ " | (?<dec> \d++ (?:'(?&dec))?+)" & @CRLF & _ " )" & @CRLF & _ " (?:[uU](?:ll|LL|[lLzZ])?+)?+" & @CRLF & _ " )" & @CRLF & _ " (?<float_literal>[-+]?+\s*+" & @CRLF & _ " (?:" & @CRLF & _ " 0[xX] (?&hex)" & @CRLF & _ " (?: \.(?&hex) (?<matched>))?+" & @CRLF & _ " (?:[pP][-=]?+(?&hex) (?<matched>))?+" & @CRLF & _ " (?(matched)|(?!)) # at least one of the above must match" & @CRLF & _ " | (?&dec)" & @CRLF & _ " (?: \.(?&dec) (?<matched>))?+" & @CRLF & _ " (?:[eE][-=]?+(?&dec) (?<matched>))?+" & @CRLF & _ " (?(matched)|(?!)) # at least one of the above must match" & @CRLF & _ " )" & @CRLF & _ " (?:f16|f32|f64|f128|bf16|F16|F32|F64|F128|BF16|[flFL])?+" & @CRLF & _ " )" & @CRLF & _ " (?<literal> (?&string_literal) | (?&float_literal) | (?&int_literal) )" & @CRLF & _ "" & @CRLF & _ " (?<token>(?&literal) | (?&rem))" & @CRLF & _ " (?<params> \((?:(?&token)|[^()] | (?&params))*+\))" & @CRLF & _ " (?<tparams> <(?:(?&token)|[^<>()]|(?&tparams) |(?&params))*+> )" & @CRLF & _ " (?<brace_list> \{(?:(?&token)|[^{}()]|(?&brace_list)|(?&params))*+\})" & @CRLF & _ " (?<index> \[(?:(?&token)|[^[\]] |(?&index) )*+\])" & @CRLF & _ " (?<lambda_capture> (?&index)) # not the same but this will still match it correctly" & @CRLF & _ "" & @CRLF & _ " # a simple symbol" & @CRLF & _ " (?<symbol>[a-zA-Z_][a-zA-Z\d_]*+)" & @CRLF & _ " # symbols used for operator overloading" & @CRLF & _ " (?<operator_symbol>" & @CRLF & _ " operator\s*+" & @CRLF & _ " (?:" & @CRLF & _ " &&|\|\||\[\]|\(\)|\+\+|--|""|<=>|->\*?+|,|(?:new|delete)(?:\s*+(?:\[\]))?+" & @CRLF & _ " | (?:<<|>>|[-+~!%^&*<=>])=?+" & @CRLF & _ " | (?&type)" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ "" & @CRLF & _ " (?<scoped_type_symbol_name>" & @CRLF & _ " (?:::\s*+)?+" & @CRLF & _ " (?<scoped_type_symbol_name_helper>" & @CRLF & _ " (?:template(?<template_keyword_matched>)\s++)?+" & @CRLF & _ " (?&symbol)\s*+" & @CRLF & _ " # Check for template parameters" & @CRLF & _ " (?(template_keyword_matched)" & @CRLF & _ " # MANDITORY if template keyword is used." & @CRLF & _ " (?:(?&tparams)\s*+)" & @CRLF & _ " | # OPTIONAL if template keyword is omitted." & @CRLF & _ " # TODO: Look into possible edge cases where this might" & @CRLF & _ " # not work as expected." & @CRLF & _ " (?:(?&tparams)\s*+)?+ " & @CRLF & _ " )" & @CRLF & _ " (?:\s*+::\s*+(?&scoped_type_symbol_name_helper))?+" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ "" & @CRLF & _ " (?<scoped_value_symbol_name>" & @CRLF & _ " (?:::\s*+)?+" & @CRLF & _ " (?<scoped_value_symbol_name_helper>" & @CRLF & _ " (?:template(?<template_keyword_matched>)\s++)?+" & @CRLF & _ " (?:(?&operator_symbol)(?<operator_symbol_matched>)|(?&symbol))\s*+" & @CRLF & _ " # Check for template parameters" & @CRLF & _ " (?(template_keyword_matched)" & @CRLF & _ " # MANDITORY if template keyword is used." & @CRLF & _ " (?:(?&tparams)\s*+)" & @CRLF & _ " | # OPTIONAL if template keyword is omitted." & @CRLF & _ " # TODO: Look into possible edge cases where this might" & @CRLF & _ " # not work as expected." & @CRLF & _ " (?:(?&tparams)\s*+)?+ " & @CRLF & _ " )" & @CRLF & _ " (?(operator_symbol_matched)" & @CRLF & _ " # Operator symbol is at deepest scope." & @CRLF & _ " | # If didn't match operator symbol, then see if there is a deeper scope" & @CRLF & _ " (?:\s*+::\s*+(?&scoped_value_symbol_name_helper))?+" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ "" & @CRLF & _ " # types" & @CRLF & _ " (?<cv>" & @CRLF & _ " const \b(?:\s++volitile\b)?+" & @CRLF & _ " | volitile\b(?:\s++const \b)?+" & @CRLF & _ " )" & @CRLF & _ " (?<user_type>" & @CRLF & _ " (?:typename\s*+)?+" & @CRLF & _ " (?&scoped_type_symbol_name)" & @CRLF & _ " )" & @CRLF & _ "" & @CRLF & _ " (?<type>" & @CRLF & _ " # not going to do function pointers yet" & @CRLF & _ " (?:(?&cv)\s++)?+" & @CRLF & _ " (?:auto\b" & @CRLF & _ " # Yes, this will capture illegal types such as short char, but I'm ok with that." & @CRLF & _ " # This is to help document, not validate the code!" & @CRLF & _ " | (?: (?:(?:un)?+signed) \b (?<matched>))?+" & @CRLF & _ " (?:\s*+ (?:short|long) \b (?<matched>))?+" & @CRLF & _ " (?:\s*+ (?:long) \b (?<matched>))?+" & @CRLF & _ " (?:\s*+ (?:int|char) \b (?<matched>))?+" & @CRLF & _ " (?(matched)|(?!)) # at least one of the items above must have matched" & @CRLF & _ " | ((?:long\s++)?+double|float)\b" & @CRLF & _ " | decltype\s*+(?&params)" & @CRLF & _ " | (?&user_type)" & @CRLF & _ " )" & @CRLF & _ " (?:\s*+(?&cv))?+" & @CRLF & _ " # pointers" & @CRLF & _ " (?:\s*+\*\s*+(?&cv)?+)*+" & @CRLF & _ " # reference" & @CRLF & _ " &?+" & @CRLF & _ " )" & @CRLF & _ "" & @CRLF & _ " # expressions" & @CRLF & _ " (?<fn_called_or_var>" & @CRLF & _ " (?&scoped_value_symbol_name)\s*+" & @CRLF & _ " (?&params)?+" & @CRLF & _ " )" & @CRLF & _ " (?<lambda>(?&lambda_capture)\s*+(?&params)\s*+(?&brace_list))" & @CRLF & _ " (?<evaluable>" & @CRLF & _ " (?:\*\s*+)*+ # dereference" & @CRLF & _ " (?:(?&fn_called_or_var)|(?&lambda)\s*+(?&params)|(?&params)|(?&literal))" & @CRLF & _ " (?:\s*+(?&index))*+" & @CRLF & _ " )" & @CRLF & _ " (?<binary_op> &&|<=>|<<|>>|\|\||[-+*/%|&<=>])" & @CRLF & _ " (?<unary_prefix_op> --|\+\+|[-+!~])" & @CRLF & _ " (?<unary_suffix_op> --|\+\+)" & @CRLF & _ "" & @CRLF & _ " (?<expression>" & @CRLF & _ " (?:(?&unary_prefix_op)++\s*+)?+(?&evaluable)(\s*+(?&unary_suffix_op)++)?+" & @CRLF & _ " (?:\s*+(?&binary_op)\s*+(?&expression))*+" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ " (?<whitespace>^[ \t]*+)" & @CRLF & _ " (?:" & @CRLF & _ " # check for enum" & @CRLF & _ " enum\s++(?<enum_name>(?&symbol))" & @CRLF & _ " | # check for template" & @CRLF & _ " (?:template\s*+(?<template_parameters>(?&tparams)))?+\s*+" & @CRLF & _ " (?:" & @CRLF & _ " # check for struct/class" & @CRLF & _ " (?:struct|class)\s++(?<class_name>(?&symbol))" & @CRLF & _ " | # check for function or variable" & @CRLF & _ " (?<extern>extern\s++)?+" & @CRLF & _ " (?<static>static\s++)?+" & @CRLF & _ " (?<constexpr>constexpr\s++)?+" & @CRLF & _ " (?<static>static\s++)?+" & @CRLF & _ " (?<return_type>auto(?<auto_return_type>)|(?&type))\s*+" & @CRLF & _ " (?<symbol_name>(?&scoped_value_symbol_name))\s*+" & @CRLF & _ " (?<function_parameters>(?&params)" & @CRLF & _ " (?(auto_return_type)" & @CRLF & _ " # optional trailing return type" & @CRLF & _ " (?:\s*+->\s*+(?<return_type>(?&type)))?+" & @CRLF & _ " )" & @CRLF & _ " )?+" & @CRLF & _ " )" & @CRLF & _ " )" & @CRLF & _ "" Local $sString = "" & @CRLF & _ " template <typename ElementGenerator, typename StoredType, typename...Rest>" & @CRLF & _ " constexpr auto generate_tuple(" & @CRLF & _ " ElementGenerator&& element_generator, DiagnosticReportCode code, bool database_query, StoredType" & @CRLF & _ " , Rest&&...args" & @CRLF & _ " ) {" & @CRLF & _ " static_assert(!std::is_same<StoredType, DiagnosticReportCode>::value" & @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