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

/
/
gm

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)\b((?<street>(\p{L}[ ]?[-.]*)+ [0-9]{1,3}([ ]?[A-Za-z])?))\b|\b((?<zipcode>([A-Z-]+)?[0-9]+)[, ](?<city>(\p{L}[- ]?)+))\b" Local $sString = "Michael Hohmann P.v.-Mallinckrodt-Weg 13a" & @CRLF & _ "Experte für Marketing Automatisierung 33154 Salzkotten" & @CRLF & _ "" & @CRLF & _ " Tel: (0 52 58) 9 90 90-0" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Dianastraße 1 030 - 40 39 33 33" & @CRLF & _ "13469 Berlin mhugo@stahlsdfsdf.berlin" & @CRLF & _ "" & @CRLF & _ "Dipl.Ing. Arch. Innenraum Großgörschenstrasse 5" & @CRLF & _ "" & @CRLF & _ "10827 Berlin Schöneberg" & @CRLF & _ "" & @CRLF & _ "Geschäftsführer Gubeslstrasse 24" & @CRLF & _ "" & @CRLF & _ "M +41 79 999 99 99 CH-6300 Zug" & @CRLF & _ "" & @CRLF & _ "Friedrichstraße 94" & @CRLF & _ "Telefon +49 30 33333-33333 10117 Berlin" & @CRLF & _ "" & @CRLF & _ "Mobil +49 333 3333333 Lichtenberger Straße 17 a" & @CRLF & _ "" & @CRLF & _ "wilfreid.kroll@sdfsdf.de 10243 Berlin" & @CRLF & _ "" & @CRLF & _ "Unit 13, Le Moulin, Rue de Bali" & @CRLF & _ "Pereybére 99999, Mauritius" & @CRLF & _ "" & @CRLF & _ "Wolfgang Leobner Unterer Grund 10" & @CRLF & _ "Ressavarstraße 45, A-9384 Hartberg" & @CRLF & _ "" & @CRLF & _ "General Manager Horbeller Straße 33" & @CRLF & _ "" & @CRLF & _ "Poppelsdorfer Allee 89" & @CRLF & _ "93828 Bonn" & @CRLF & _ "" & @CRLF & _ "Carl-Benz-Straße 13" & @CRLF & _ "D-82937 Schweinfurt" & @CRLF & _ "" & @CRLF & _ "Luisenstraße 33 | 93720 Bad Dürrheim" & @CRLF & _ "" & @CRLF & _ "Schwändi 7 * 8486 Rikon" & @CRLF & _ "" & @CRLF & _ "Bogener Straße 8 94827 Neukirchen" & @CRLF & _ "" & @CRLF & _ "93939 Neuötting" & @CRLF & _ "" & @CRLF & _ "83927 Mannheim-Schönau" & @CRLF & _ "" & @CRLF & _ "Wörrst Straße 3" & @CRLF & _ "" & @CRLF & _ "Türrschmidtstr. 2a" & @CRLF & _ "" & @CRLF & _ "Lambertusweg 2" & @CRLF & _ "" & @CRLF & _ "Lerchenweg 4 " & @CRLF & _ "" & @CRLF & _ "D-29304 Eching am Ammersee" & @CRLF & _ "" & @CRLF & _ "Schönbuchstr. 34" & @CRLF & _ "" & @CRLF & _ "Neuenhofer Str. 7" & @CRLF & _ "" & @CRLF & _ "Meinekeestr. 26, 29304 Berlin" & @CRLF & _ "" & @CRLF & _ "Carmenstraße 17 - 18" & @CRLF & _ "" & @CRLF & _ "13432 Werder (Havel)" & @CRLF & _ "" & @CRLF & _ "Lenelshof 1 99930 Ratingen" & @CRLF & _ "" & @CRLF & _ "Rothenbasdfchaussee 80c" & @CRLF & _ "" & @CRLF & _ "Poller Kirchweg 990" & @CRLF & _ "Poller Kirchweg 9903" & @CRLF & _ "" & @CRLF & _ "Weilstetter Weg 34B" & @CRLF & _ "" & @CRLF & _ "Gartenstraße 88U Fax: 93 (0) 33333 - 33333" & @CRLF & _ "" & @CRLF & _ "09392 Crottendorf Email: info@sdfsdf.de" & @CRLF & _ "" & @CRLF & _ "hauptstr.51" & @CRLF & _ "" & @CRLF & _ "Pantelsdfs Str. 33, A-3929 St. Pantaleon, Austria" & @CRLF & _ "" & @CRLF & _ "D - 88889 Dreieich" & @CRLF & _ "" & @CRLF & _ "Bahnhofstr. 77 93000 Kornewestheim Tel. 929293-39392" & @CRLF & _ "" & @CRLF & _ "Friedrichstraße 180 - 39302 Berlin" & @CRLF & _ "" & @CRLF & _ "Kupferteichweg 39 44444 Hamburg" & @CRLF & _ "" & @CRLF & _ "HEP Immobilien GmbH - Willicher Straße 1 - 33333 Willich" & @CRLF & _ "" & @CRLF & _ "Rosengasse 19" & @CRLF & _ "A-3456 Groß Enzersdorf" & @CRLF & _ "" & @CRLF & _ "Karsten Poppe Neue Straße 22" & @CRLF & _ "Finanz-/Versicherungmakler 33333 Wildeshausen" & @CRLF & _ "" & @CRLF & _ "" 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