Regular Expressions 101

Save & Share

  • Current Version: 28
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

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 = "(?m)(?xi)^(" & @CRLF & _ "(AT)?U[0-9]{8} | # Austria" & @CRLF & _ "(BE)?0[0-9]{9} | # Belgium" & @CRLF & _ "(BG)?[0-9]{9,10} | # Bulgaria" & @CRLF & _ "(HR)?[0-9]{11} | # Croatia" & @CRLF & _ "(CY)?[0-9]{8}L | # Cyprus" & @CRLF & _ "(CZ)?[0-9]{8,10} | # Czech Republic" & @CRLF & _ "(DE)?[0-9]{9} | # Germany" & @CRLF & _ "(DK)?[0-9]{8} | # Denmark" & @CRLF & _ "(EE)?[0-9]{9} | # Estonia" & @CRLF & _ "(EL|GR)?[0-9]{9} | # Greece" & @CRLF & _ "ES[A-Z][0-9]{7}(?:[0-9]|[A-Z]) | # Spain" & @CRLF & _ "(FI)?[0-9]{8} | # Finland" & @CRLF & _ "(FR)?[0-9A-Z]{2}[0-9]{9} | # France" & @CRLF & _ "(GB)?([0-9]{9}([0-9]{3})?|[A-Z]{2}[0-9]{3}) | # United Kingdom" & @CRLF & _ "(HU)?[0-9]{8} | # Hungary" & @CRLF & _ "(IE)?[0-9]S[0-9]{5}L | # Ireland" & @CRLF & _ "(IT)?[0-9]{11} | # Italy" & @CRLF & _ "(LT)?([0-9]{9}|[0-9]{12}) | # Lithuania" & @CRLF & _ "(LU)?[0-9]{8} | # Luxembourg" & @CRLF & _ "(LV)?[0-9]{11} | # Latvia" & @CRLF & _ "(MT)?[0-9]{8} | # Malta" & @CRLF & _ "(NL)?[0-9]{9}B[0-9]{2} | # Netherlands" & @CRLF & _ "(PL)?[0-9]{10} | # Poland" & @CRLF & _ "(PT)?[0-9]{9} | # Portugal" & @CRLF & _ "(RO)?[0-9]{2,10} | # Romania" & @CRLF & _ "(SE)?[0-9]{12} | # Sweden" & @CRLF & _ "(SI)?[0-9]{8} | # Slovenia" & @CRLF & _ "(SK)?[0-9]{10} # Slovakia" & @CRLF & _ ")$" Local $sString = "ATU99999999" & @CRLF & _ "BE0999999999" & @CRLF & _ "BG999999999" & @CRLF & _ "HR12345678901" & @CRLF & _ "CY99999999L" & @CRLF & _ "CZ12345678" & @CRLF & _ "DK99999999" & @CRLF & _ "EE123456789" & @CRLF & _ "FI99999999" & @CRLF & _ "FRXX999999999" & @CRLF & _ "DE999999999" & @CRLF & _ "EL123456789" & @CRLF & _ "HU12345678" & @CRLF & _ "IE1S23456L" & @CRLF & _ "IE1234567T" & @CRLF & _ "IE1234567TW" & @CRLF & _ "IE1234567FA" & @CRLF & _ "ESA12345678" & @CRLF & _ "ESZ1234567E" 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