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{1,4}(( |\(| \(|-)?\d{1,4}( |\)|\) |-)?)?(\d{2} )?\d{2,4}[- ]?\d{2,3}[- ]?\d{0,2}$", flags=re.MULTILINE | re.DOTALL) test_str = ("+22-22-222-2222\n" "+777(777)777-777\n" "+666-66-666-6666\n" "+9(999)999-9999\n" "+444-444-444\n" "+555(555)555-555\n" "+0(000)000-0000\n" "+1(111)111-1111\n" "+11(111)111-1111\n" "+111-11-111-111\n" "+666-666-6666\n" "+99 999 999 999\n" "+77(777)777-7777\n" "+999-99-999-99-99\n" "+8(888)888-8888\n" "+333-3333-3333\n" "+000-00-000-000\n" "+7(777)777-7777\n" "+111(11)111-11-11\n" "+55 555 55 55 55\n" "+222-222-2222\n" "+888-88-88-8888\n" "+4(444)444-4444\n" "+333-3-333-333\n" "+555-5-555-5555\n" "+555-55-5555\n" "+666-66-666-666\n" "+55-55-5555-5555\n" "+999-999-9999\n" "+5(555)555-5555\n" "+666-666-6666\n" "+111(111)111-111\n" "+666-66-66-6666\n" "+666-66-66-6666\n" "+666-66-666-666\n" "+000-0000-0000\n" "+2 (222) 222-2222\n" "+111(111)11-11\n" "+999-999-9999\n" "+0(000)000-0000\n" "+555-55-55-5555\n" "+444-44-44-44-44\n" "+88-8-8888-8888\n" "+11 11-11111111\n" "+77(777)777-7777\n" "+111-11-11111\n" "+666(666)666-666\n" "+999-99-999-9999\n" "+777-77-777\n" "+111 1111-1111\n" "+666-66-666-666\n" "+555-55-555-555\n" "+33-3-333-3333\n" "+666-666-6666\n" "+222-22-222-222\n" "+666(666)666-666\n" "+55 55 55 55 55\n" "+888-88-88-88-88\n" "+5(555)555-5555\n" "+7(777)777-7777\n" "+111-1-111-1111\n" "+66(666)666-6666\n" "+111 1111-1111\n" "+666-66-666-6666\n" "+333-3-333-333\n" "+000-000-0000\n" "+222-22-222-2222\n" "+666-66666\n" "+777-777-777\n" "+666-66-66666\n" "+222 22 222 22 22\n" "+33 3 33 33 33 33\n" "+333-33333-3333\n" "+777-77-77-77\n" "+999-9-99-99-99\n" "+555(555)55-55\n" "+666(666)666-666\n" "+55 555 5555555\n" "+000(000)000-000\n" "+000-000-00000\n" "+55(555)555-5555\n" "+444-44-44-44\n" "+5(555)555-5555\n" "+5(555)555-5555\n" "+111 1111-1111\n" "+444-44-444-444\n" "+555-5-555555\n" "+222-222-2222\n" "+333 3333-3333\n" "+000-0000-0000\n" "+666 6666 6666\n" "+88(888)888-888\n" "+222 222 2222\n" "+22 22222-22222\n" "+77-77-777-77\n" "+11(111)111-1111\n" "+333(333)333-3333\n" "+111 11 1111111\n" "+999-9-999-9999\n" "+99 999 999999\n" "+7(777)777-7777\n" "+99 999 99 9999\n" "+000-0-0000-0000\n" "+2 222 222-22-22\n" "+444-444-444444\n" "+222-22-222\n" "+777-7777-7777\n" "+111(111)111-111\n" "+000-00-000-000\n" "+444-44-444-444\n" "+999-9-999-999\n" "+111-1-111-1111\n" "+888-88-888-888\n" "+666-66-666-666\n" "+333(333)333-3333\n" "+666(666)66-666\n" "+222(222)222-222\n" "+111-1111-1111\n" "+999-99-999-999\n" "+222-22-22-22222\n" "+555-5-5555-5555\n" "+33 33-3333-3333\n" "+000-000-0000\n" "+222-22-22-2222\n" "+333-3333-3333\n" "+555-555-5555\n" "+555(555)55-55-55\n" "+111-11-11-1111\n" "+777-777-7777\n" "+11-11-11-1111\n" "+999-999-9999\n" "+666-6666-6666\n" "+444-44-444-444\n" "+111-11-11-1111\n" "+999-99-999-999\n" "+0(000)000-0000\n" "+333-33-3333-333\n" "+333-33-333-333\n" "+33-333-333\n" "+888-88-888-8888\n" "+333-333-3333\n" "+777-77-777-777\n" "+44 44 44444444\n" "+888-88-8888\n" "+44 444-444-4444\n" "+777-7777-7777\n" "+444-44-44-4444\n" "+222-22-222-22\n" "+222-2222\n" "+333-333-333\n" "+222-222-222\n" "+2(222)222-2222\n" "+66 666 66 666\n" "+666-66-666-666\n" "+44 444-4444444\n" "+666-666-6666\n" "+555-55-555-5555\n" "+000-000-0000\n" "+666(666)66-666\n" "+222(222)222-222\n" "+44(444)444-444\n" "+11 111 1111\n" "+88 888-888-888\n" "+222-22-222-2222\n" "+111-1111-1111\n" "+888-88888-8888\n" "+99-99-999-9999\n" "+2 222 222-22-22\n" "+999(999)999-999\n" "+4(444)444-4444\n" "+6(666)666-6666\n" "+2(222)222-2222\n" "+999-99-9999\n" "+111-1111-111111\n" "+777-77-77777\n" "+222-2-222-2222\n" "+222-22-222-2222\n" "+555-55-555-5555\n" "+222-2-222-222\n" "+222-22-222222\n" "+11 1111-1111\n" "+2(222)222-2222\n" "+111(111)111-111\n" "+777-77-777-777\n" "+777-77777\n" "+777-7-777-777\n" "+99-99-999-9999\n" "+44-44-444-4444\n" "+222-22-222-2222\n" "+77 777 777 777\n" "+55-55-555-5555\n" "+555-55-555-5555\n" "+444-444-444\n" "+999-99-99-9999\n" "+77 77 777 77 77\n" "+55 55 555 55 55\n" "+999-99-9999-999\n" "+999-9999-9999\n" "+888-88-888-8888\n" "+333-33-333-3333\n" "+44-44-444-444\n" "+222-222-2222\n" "+777-77-777-777\n" "+777-7777\n" "+333-33333\n" "+5(555)555-5555\n" "+444-44-444-444\n" "+44 444 444 44 44\n" "+777-7-777-7777\n" "+1(111)111-1111\n" "+222-22222\n" "+2(222)222-2222\n" "+111(111)111-111\n" "+000(00)000-00-00\n" "+000-0-000-0000\n" "+77 7777 777777\n" "+2 (222) 222-2222\n" "+666-6-666-66-66\n" "+666-66-666-6666\n" "+111-11111\n" "+11 11 1111 1111\n" "+00(000)000-0000\n" "+33-33-3333-333\n" "+444-44-4444\n" "+444-4-444-444\n" "+888-88-888-8888\n" "+555-5-555555") 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