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

/
/
gm

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"^\"(.*)\n([\w ]+)(\d*)\n\(([\d\.]+), ([\d\-\.]+)\)\"" test_str = ("Location\n" "\"11305 Cezanne St\n" "78726\n" "(30.44945, -97.820962)\"\n" "\"12904 Schleicher Trl\n" "78732\n" "(30.381982, -97.893992)\"\n" "\"11511 Catalonia Dr\n" "78759\n" "(30.410825, -97.739233)\"\n" "\"11511 Catalonia Dr\n" "78759\n" "(30.410825, -97.739233)\"\n" "\"4809 Clear View Dr\n" "78725\n" "(30.244094, -97.581411)\"\n" "\"4809 Clear View Dr\n" "78725\n" "(30.244094, -97.581411)\"\n" "\"4809 Clear View Dr\n" "78725\n" "(30.244094, -97.581411)\"\n" "\"13101 Winding Creek Rd\n" "78736\n" "(30.240521, -97.992054)\"\n" "\"705 Texas St\n" "78705\n" "(30.296976, -97.728619)\"\n" "\"2401 Cecil Dr\n" "78744\n" "(30.165036, -97.773046)\"\n" "\"2401 Cecil Dr\n" "78744\n" "(30.165036, -97.773046)\"\n" "\"905 Tudor House Road\n" "78660\n" "(30.421455, -97.640466)\"\n" "\"2718 Jorwoods Dr\n" "78745\n" "(30.201192, -97.8219)\"\n" "\"1411 Justin Ln\n" "78757\n" "(30.341012, -97.727488)\"\n" "\"2520 East 3rd St\n" "78702\n" "(30.255757, -97.714748)\"\n" "\"4420 Dovemeadow Dr\n" "78744\n" "(30.188978, -97.750916)\"\n" "\"903 Vincent Place\n" "78660\n" "(30.443792, -97.651432)\"\n" "\"903 Vincent Place\n" "78660\n" "(30.443792, -97.651432)\"\n" "\"6501 Corpus Christi Dr\n" "78729\n" "(30.446164, -97.745231)\"\n" "\"14329 Teacup Ln\n" "78660\n" "(30.418031, -97.636836)\"\n" "\"14329 Teacup Ln\n" "78660\n" "(30.418031, -97.636836)\"\n" "\"9211 Lauralan Dr\n" "78736\n" "(30.244022, -97.90871)\"\n" "\"4812 Candletree Ln\n" "78744\n" "(30.188373, -97.746254)\"\n" "\"15109 Holly Ln\n" "78734\n" "(30.366232, -97.94599)\"\n" "\"20608 Ed Acklin Rd\n" "78653\n" "(30.27638, -97.491359)\"\n" "\"7600 Bloomfield Ave\n" "78745\n" "(30.204975, -97.828903)\"\n" "\"2815 Rockridge Dr\n" "78744\n" "(30.182879, -97.753569)\"\n" "\"1712 Whitney Way\n" "78741\n" "(30.230474, -97.710957)\"\n" "\"1709 Shadowview Dr\n" "78758\n" "(30.410606, -97.690225)\"\n" "\"1302 Lipan Trl\n" "78733\n" "(30.339241, -97.870507)\"\n" "\"5336 Magdelena Dr\n" "78704\n" "(30.257628, -97.833678)\"\n" "\"1302 Canyon Edge Dr\n" "78733\n" "(30.336086, -97.864308)\"\n" "\"2401 Emmett Pkwy\n" "78728\n" "(30.452399, -97.6777)\"\n" "\"5931 Cape Coral Dr\n" "78746\n" "(30.278948, -97.836075)\"\n" "\"11929 Rosethorn Dr\n" "78758\n" "(30.400145, -97.700419)\"\n" "\"11504 Murcia Dr\n" "78759\n" "(30.40992, -97.738795)\"\n" "\"7002 Montana St\n" "78741\n" "(30.22887, -97.691651)\"\n" "\"3703 Grayson Ln\n" "78722\n" "(30.288216, -97.708994)\"\n" "\"1205 Quail Park Dr\n" "78758\n" "(30.36542, -97.706031)\"\n" "\"11824 Morning View Dr\n" "78617\n" "(30.15393, -97.647847)\"\n" "\"11824 Morning View Dr\n" "78617\n" "(30.15393, -97.647847)\"\n" "\"7400 Espina Drive\n" "78739\n" "(30.184836, -97.917651)\"\n" "\"4707 Carsonhill Dr\n" "78723\n" "(30.288232, -97.676602)\"\n" "\"14028 Lakeview Dr\n" "78732\n" "(30.414996, -97.893207)\"\n" "\"18300 Belfry Pass\n" "78653\n" "(30.316997, -97.530072)\"\n" "\"7916 Adelaide Dr\n" "78739\n" "(30.19158, -97.919402)\"\n" "\"1512 Miss Allisons Way\n" "78660\n" "(30.447836, -97.65996)\"\n" "\"911 Peggotty Pl\n" "78753\n" "(30.387673, -97.66531)\"\n" "\"7005 Bright Star Ln\n" "78736\n" "(30.249735, -97.908418)\"\n" "\"2815 Oak Ridge Dr\n" "78669\n" "(30.36881, -98.036181)\"\n" "\"2815 Oak Ridge Dr\n" "78669\n" "(30.36881, -98.036181)\"\n" "\"4704 Sunridge Ct\n" "78741\n" "(30.219579, -97.727328)\"\n" "\"7128 Mumruffin Ln\n" "78754\n" "(30.344789, -97.610169)\"\n" "\"7701 Callbram Ln\n" "78736\n" "(30.233262, -97.89253)\"\n" "\"6604 Jamaica Ct\n" "78757\n" "(30.347375, -97.748886)\"\n" "\"3415 Sweetgum\n" "Trc 78713\n" "(30.459228, -97.824468)\"\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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