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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

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

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php