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
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

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @/ ((((\+49(\s?))|(049(\s?))?)[.\-\\\/]*?((\(0\))|0)?\s?(151|152|157|159|160|162|163|17)|((\+43(\s?))|(043(\s?))?)[.\-\\\/]*?((\(0\))|0)?\s?(650|660|663|664|676|678|680|681|688|699)|((\+41(\s?))|(041(\s?))?)[.\-\\\/]*?((\(0\))|0)?\s?(76|77|78|79)))([ .\-\\\/]*[0-9]+){7,} /; string input = @"=================================== ====== sms phone ================== =================================== Fon +49 33 27. 46 88 13 Fax +49 33 27. 46 88 46 +49 (0) 173 / 241 38 66 Neuenhofer Str. 6 Tel. 02244 - 8 79 96 39 53639 Königswinter Mobil: 0151 - 23 58 73 18 tel 030/ 5779 9182 fax 030/ 5779 9182 mob 0178/ 935 44 00 Tel. +49 (0) 9283 - 920 39 01 Fax +49 (0) 9283 - 920 391 Fon +99-99 99-9 9 99 99- 98 Mobil +49 - 177 - 999 99 99 Tel.: +49 (0) 99 99 - 77 999 777 0171 -99 99 99 99 0171 - 99 99 99 99 071195836855 210 Shepherd's Bush Road +49 30 340 604 760 +49 30 340 604 760 Phone: +49 177 2837460 ZAV Köln: +49 221 29304928 Tel +49 (0)8143 999500 Fax +49 (0)8143 999500 Mobil +49 (0)8143 999500 +49 (0) 6731 99 77 99 6 +49 173 9292927 +49 -(0) 173 9292927 Tel. 0621 939393 Memeler Straße 15 Fax 0283 9193940 67294 Mannheim-Schönau +41 79 419 84 55 Tel. 02938 9987-12 Fax 02938 9987-12 030.20 14 32 34 Aparmenthotel ***** Telefon +49 (0) 9928 444 09-100 +49(0)23459302939577777 Mobil: +49 (0) 889 9999 9999 T: +43 (0)9999 99 999, F: +43 (0)9999 99 999-4 Tel.: +49 9999 9999999 Mobile (Mauritius): +230 00 00 00 00 Phone (Germany): +49 (351) 222 22 22 Telefon +49 99 99999-77777 92927 Berlin Fax +49 99 99999-77777 Besucheranschrift: Mobil +49 992 9999977777 Lichtenberger Straße 29 a 0171-99 99 99 99 040 6026770 s.goetze@provin.net Mobil 0170-7934869 E-Email: leglos@athanasia-coaching.de steffen.sprattler@consigno.net T+41 844 266 744 mobil: +23 (0) 234 342 kiel@h-faktor.de www.h-faktor.de "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx