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)^(?:(?P<name>[\p{L}\.\ ]+)\n)?" & @CRLF & _ "(?:(?P<co>[\p{L}\.\ \/]+)\n)?" & @CRLF & _ "(?P<street>[\p{L}\ \p{N}’\.]+)\n" & @CRLF & _ "(?:(?<city>[\p{L}\ ]+)\n)?" & @CRLF & _ "(?P<postal_code>[\p{N}\ ]+)\ (?P<postal_city>[\p{L}\ ]+)(?:\((?<province>[\p{L}\ ]+)\))?\n" & @CRLF & _ "(?P<country>[\p{L}\ ]+)?" & @CRLF & _ "$" Local $sString = "Herr Franz Huber" & @CRLF & _ "Beethovenstrasse 12" & @CRLF & _ "1010 WIEN" & @CRLF & _ "AUSTRIA" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr Willy Janssens" & @CRLF & _ "Lange Stationsstraat 352" & @CRLF & _ "3000 LEUVEN" & @CRLF & _ "BELGIUM" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "M. Emile Dubois" & @CRLF & _ "Rue du Diamant 215" & @CRLF & _ "4800 VERVIERS" & @CRLF & _ "BELGIUM" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr Thor Nielsen" & @CRLF & _ "Tietgensgade 137" & @CRLF & _ "8800 VIBORG" & @CRLF & _ "DENMARK" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr Torben Raldorf" & @CRLF & _ "PO Box 100" & @CRLF & _ "COPENHAGEN" & @CRLF & _ "1004 VIBORG" & @CRLF & _ "DENMARK" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Peter Mogensen" & @CRLF & _ "c/o Fictional Company" & @CRLF & _ "Niels Bohrs Alle 23" & @CRLF & _ "Dalum" & @CRLF & _ "5230 Odense M" & @CRLF & _ "Danmark" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr Asko Teirila" & @CRLF & _ "PO Box 511" & @CRLF & _ "39140 AKDENMAA" & @CRLF & _ "FINLAND" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "M. Robert MARIN" & @CRLF & _ "Rue de l’Eglise" & @CRLF & _ "Dunes" & @CRLF & _ "82340 AUVILLAR" & @CRLF & _ "FRANCE" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mme Marie PAGE" & @CRLF & _ "23 Rue de Grenell" & @CRLF & _ "75700 PARIS CEDEX" & @CRLF & _ "FRANCE" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mrs F Meier" & @CRLF & _ "Weberstr. 2" & @CRLF & _ "53113 BONNN" & @CRLF & _ "GERMANY" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr P Kunde" & @CRLF & _ "Lange Str. 12" & @CRLF & _ "04103 LEIPZIG" & @CRLF & _ "GERMANY" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr George Latsis" & @CRLF & _ "Alkamenou 37" & @CRLF & _ "117 80 ATHENS" & @CRLF & _ "GREECE" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr Jon Jonsson" & @CRLF & _ "Einimel 80" & @CRLF & _ "107 REYKJAVIK" & @CRLF & _ "ICELAND" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Sig. Giovanni Masci" & @CRLF & _ "via Garibaldi 27" & @CRLF & _ "47037 RIMINI RN" & @CRLF & _ "ITALY" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "M. Jaques Muller" & @CRLF & _ "71 route de Longway" & @CRLF & _ "4750 PETANGE" & @CRLF & _ "LUXEMBOURG" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Mr J van Dieten" & @CRLF & _ "Morsstr 111" & @CRLF & _ "2312 BK LEIDEN" & @CRLF & _ "THE NETHERLANDS" & @CRLF & _ "(There should be a double space between the postcode and the post town)" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Herr Hans Hansen" & @CRLF & _ "Svingen 22" & @CRLF & _ "9230 BEKKEHAUG" & @CRLF & _ "NORWAY" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Senhor Carlos Manuel Pereira" & @CRLF & _ "Av das A’Augsa Livres" & @CRLF & _ "Monte Trigo" & @CRLF & _ "7220 PORTEL" & @CRLF & _ "PORTUGAL" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Rosalina Silva" & @CRLF & _ "R Conde Redondo 80" & @CRLF & _ "1192 LISBOA CODEX" & @CRLF & _ "PORTUGAL" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Sra Ana Jimenez" & @CRLF & _ "Mimbreras 4A" & @CRLF & _ "03201 ELCHE (Alicante)" & @CRLF & _ "SPAIN" & @CRLF & _ "(The province should be included in brackets after the town)" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Fru Inger Lilja" & @CRLF & _ "Vasavagen 3 4tr" & @CRLF & _ "582 20 LINKOPING" & @CRLF & _ "SWEDEN" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "M. Andre Perret" & @CRLF & _ "Schanzenstrasse 7" & @CRLF & _ "3030 BERNE" & @CRLF & _ "SWITZERLAND" 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