Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"^(\(?([\d \-\)\–\+\/\(.]+){5}\)?([ .\-–\/]?)([\d]+))$", flags=re.MULTILINE) test_str = ("US (North American) Phone Numbers\n" "1-800-123-4567\n" "(123)456-7890\n" "1234567890\n" "123-456-7890\n" "123.456.7890\n" "123 456 7890\n" "(123) 456 7890\n" "UK Phone Numbers\n" "+447222555555\n" "+44 7222 555 555\n" "(0722) 5555555 #2222\n" "French Phone Numbers\n" "0123456789\n" "01 23 45 67 89\n" "01.23.45.67.89\n" "0123 45.67.89\n" "0033 123-456-789\n" "+33-1.23.45.67.89\n" "+33 – 123 456 789\n" "+33(0) 123 456 789\n" "+33 (0)123 45 67 89\n" "+33 (0)1 2345-6789\n" "+33(0) – 123456789\n" "German Phone Numbers\n" "(06442) 3933023\n" "(02852) 5996-0\n" "(042) 1818 87 9919\n" "06442 / 3893023\n" "06442 / 38 93 02 3\n" "06442/3839023\n" "042/ 88 17 890 0\n" "+49 221 549144 – 79\n" "+49 221 – 542194 79\n" "+49 (221) – 542944 79\n" "0 52 22 – 9 50 93 10\n" "+49(0)121-79536 – 77\n" "+49(0)2221-39938-113\n" "+49 (0) 1739 906-44\n" "+49 (173) 1799 806-44\n" "0214154914479\n" "02141 54 91 44 79\n" "01517953677\n" "+491517953677\n" "015777953677\n" "02162 – 54 91 44 79\n" "(02162) 54 91 44 79\n" "Chinese Phone Numbers\n" "0936-4211235\n" "89076543\n" "010-12345678-1234\n" "Chinese Mobile Phone Numbers\n" "008618311006933\n" "+8617888829981\n" "1911925564\n" "India Phone Numbers\n" "03595-259506\n" "03592 245902\n" "03598245785\n" "9775876662\n" "0 9754845789\n" "0-9778545896\n" "+91 9456211568\n" "91 9857842356\n" "919578965389\n" "Brazilian Phone Numbers\n" "(12) 123 1234\n" "(01512) 123 1234\n" "(0xx12) 1234 1234\n" "Australian Phone Numbers\n" "0732105432\n" "1300333444\n" "131313\n" "Dutch Phone Numbers\n" "+31235256677\n" "+31(0)235256677\n" "023-5256677\n" "Sweden Phone Numbers\n" "+46 8 123 456 78\n" "08-123 456 78\n" "0123-456 78\n" "thx to https://regexpattern.com/phone-number/") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html