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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "((((\\+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,}"; final String string = "===================================\n" + "====== sms phone ==================\n" + "===================================\n\n" + "Fon +49 33 27. 46 88 13\n" + "Fax +49 33 27. 46 88 46\n\n" + "+49 (0) 173 / 241 38 66\n\n" + "Neuenhofer Str. 6 Tel. 02244 - 8 79 96 39\n" + "53639 Königswinter Mobil: 0151 - 23 58 73 18\n\n" + "tel 030/ 5779 9182\n" + "fax 030/ 5779 9182\n" + "mob 0178/ 935 44 00\n\n" + "Tel. +49 (0) 9283 - 920 39 01\n" + "Fax +49 (0) 9283 - 920 391\n\n" + "Fon +99-99 99-9 9 99 99- 98\n" + "Mobil +49 - 177 - 999 99 99\n\n" + "Tel.: +49 (0) 99 99 - 77 999 777\n\n" + "0171 -99 99 99 99\n" + "0171 - 99 99 99 99\n\n" + "071195836855\n\n" + "210 Shepherd's Bush Road +49 30 340 604 760\n\n" + "+49 30 340 604 760\n\n" + "Phone: +49 177 2837460\n" + "ZAV Köln: +49 221 29304928\n\n" + "Tel +49 (0)8143 999500\n" + "Fax +49 (0)8143 999500\n" + "Mobil +49 (0)8143 999500\n\n" + "+49 (0) 6731 99 77 99 6\n\n" + "+49 173 9292927\n\n" + "+49 -(0) 173 9292927\n\n" + "Tel. 0621 939393 Memeler Straße 15\n" + "Fax 0283 9193940 67294 Mannheim-Schönau\n\n\n" + "+41 79 419 84 55\n\n" + "Tel. 02938 9987-12\n" + "Fax 02938 9987-12\n\n" + "030.20 14 32 34\n\n" + "Aparmenthotel ***** Telefon +49 (0) 9928 444 09-100\n\n" + "+49(0)23459302939577777\n\n\n" + "Mobil: +49 (0) 889 9999 9999\n\n\n" + "T: +43 (0)9999 99 999, F: +43 (0)9999 99 999-4\n\n" + "Tel.: +49 9999 9999999\n\n" + "Mobile (Mauritius): +230 00 00 00 00\n" + "Phone (Germany): +49 (351) 222 22 22\n\n" + "Telefon +49 99 99999-77777 92927 Berlin\n" + "Fax +49 99 99999-77777 Besucheranschrift:\n" + "Mobil +49 992 9999977777 Lichtenberger Straße 29 a\n\n" + "0171-99 99 99 99\n\n" + "040 6026770 s.goetze@provin.net\n" + "Mobil 0170-7934869 E-Email: leglos@athanasia-coaching.de\n\n" + "steffen.sprattler@consigno.net T+41 844 266 744\n\n" + "mobil: +23 (0) 234 342 kiel@h-faktor.de www.h-faktor.de\n\n\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html