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{3})(?:(?:-*|\s*|\.*|\)*|\)\s*))(\d{3})(?:(?:-*|\s*|\.*|\)*))(\d{4})") test_str = ("ashishg e ashishg@stanford.edu\n" "ashishg e rozm@stanford.edu\n" "ashishg p 650-723-1614\n" "ashishg p 650-723-4173\n" "ashishg p 650-814-1478\n" "balaji e balaji@stanford.edu\n" "bgirod p 650-723-4539\n" "bgirod p 650-724-3648\n" "bgirod p 650-724-6354\n" "cheriton e cheriton@cs.stanford.edu\n" "cheriton e uma@cs.stanford.edu\n" "cheriton p 650-723-1131\n" "cheriton p 650-725-3726\n" "dabo e dabo@cs.stanford.edu\n" "dabo p 650-725-3897\n" "dabo p 650-725-4671\n" "dlwh e dlwh@stanford.edu\n" "engler e engler@lcs.mit.edu\n" "engler e engler@stanford.edu\n" "eroberts e eroberts@cs.stanford.edu\n" "eroberts p 650-723-3642\n" "eroberts p 650-723-6092\n" "fedkiw e fedkiw@cs.stanford.edu\n" "hager e hager@cs.jhu.edu\n" "hager p 410-516-5521\n" "hager p 410-516-5553\n" "hager p 410-516-8000\n" "hanrahan e hanrahan@cs.stanford.edu\n" "hanrahan p 650-723-0033\n" "hanrahan p 650-723-8530\n" "horowitz p 650-725-3707\n" "horowitz p 650-725-6949\n" "jks e jks@robotics.stanford.edu\n" "jurafsky e jurafsky@stanford.edu\n" "jurafsky p 650-723-5666\n" "kosecka e kosecka@cs.gmu.edu\n" "kosecka p 703-993-1710\n" "kosecka p 703-993-1876\n" "kunle e darlene@csl.stanford.edu\n" "kunle e kunle@ogun.stanford.edu\n" "kunle p 650-723-1430\n" "kunle p 650-725-3713\n" "kunle p 650-725-6949\n" "lam e lam@cs.stanford.edu\n" "lam p 650-725-3714\n" "lam p 650-725-6949\n" "latombe e asandra@cs.stanford.edu\n" "latombe e latombe@cs.stanford.edu\n" "latombe e liliana@cs.stanford.edu\n" "latombe p 650-721-6625\n" "latombe p 650-723-0350\n" "latombe p 650-723-4137\n" "latombe p 650-725-1449\n" "levoy e ada@graphics.stanford.edu\n" "levoy e melissa@graphics.stanford.edu\n" "levoy p 650-723-0033\n" "levoy p 650-724-6865\n" "levoy p 650-725-3724\n" "levoy p 650-725-4089\n" "manning e dbarros@cs.stanford.edu\n" "manning e manning@cs.stanford.edu\n" "manning p 650-723-7683\n" "manning p 650-725-1449\n" "manning p 650-725-3358\n" "nass e nass@stanford.edu\n" "nass p 650-723-5499\n" "nass p 650-725-2472\n" "nick e nick.parlante@cs.stanford.edu\n" "nick p 650-725-4727\n" "ok p 650-723-9753\n" "ok p 650-725-1449\n" "ouster e teresa.lynn@stanford.edu\n" "ouster e ouster@cs.stanford.edu\n" "pal e pal@cs.stanford.edu\n" "pal p 650-725-9046\n" "psyoung e patrick.young@stanford.edu\n" "rajeev p 650-723-4377\n" "rajeev p 650-723-6045\n" "rajeev p 650-725-4671\n" "rinard e rinard@lcs.mit.edu\n" "rinard p 617-253-1221\n" "rinard p 617-258-6922\n" "serafim e serafim@cs.stanford.edu\n" "serafim p 650-723-3334\n" "serafim p 650-725-1449\n" "shoham e shoham@stanford.edu\n" "shoham p 650-723-3432\n" "shoham p 650-725-1449\n" "subh e subh@stanford.edu\n" "subh e uma@cs.stanford.edu\n" "subh p 650-724-1915\n" "subh p 650-725-3726\n" "subh p 650-725-6949\n" "thm e pkrokel@stanford.edu\n" "thm p 650-725-3383\n" "thm p 650-725-3636\n" "thm p 650-725-3938\n" "tim p 650-724-9147\n" "tim p 650-725-2340\n" "tim p 650-725-4671\n" "ullman e support@gradiance.com\n" "ullman e ullman@cs.stanford.edu\n" "ullman p 650-494-8016\n" "ullman p 650-725-2588\n" "ullman p 650-725-4802\n" "vladlen e vladlen@stanford.edu\n" "widom e siroker@cs.stanford.edu\n" "widom e widom@cs.stanford.edu\n" "widom p 650-723-0872\n" "widom p 650-723-7690\n" "widom p 650-725-2588\n" "zelenski e zelenski@cs.stanford.edu\n" "zelenski p 650-723-6092\n" "zelenski p 650-725-8596\n" "zm e manna@cs.stanford.edu\n" "zm p 650-723-4364\n" "zm p 650-725-4671\n" "650-725-4671\n" "650-725-4671\n" "6103564533\n" "(610)3564533\n" "(610) 356-4533 \n" "610.405.0420\n" "6104050420\n" "16104050420\n" "610.405-0420\n" "610.405-0420\n\n\n\n\n") 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