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

Substitution

Processing...

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"^\"[\w ]+ \w*. \w*.\d*.\nTX \d*\n\((\d*.+), (\-\d*.\d*)\)\"" test_str = ("Location\n" "\"3415 Sweetgum Trc\n" "TX 78713\n" "(30.459330, -97.824449)\"\n" "\"4420 Dovemeadow Dr\n" "TX 78744\n" "(30.188962, -97.750896)\"\n" "\"7400 Espira Drive\n" "TX 78739\n" "(30.184748, -97.917591)\"\n" "\"9321 Bavaria Ln.\n" "TX 78749\n" "(30.202255, -97.874029)\"\n" "\"11504 Murcia Dr\n" "TX 78759\n" "(30.409891, -97.738812)\"\n" "\"13101 Winding Creek Rd\n" "TX 78736\n" "(30.240521, -97.992054)\"\n" "\"7128 Mumruffin Ln\n" "TX 78754\n" "(30.34478, -97.61014)\"\n" "\"2815 Oak Ridge Dr\n" "TX 78669\n" "(30.368907, -98.036141)\"\n" "\"903 Vincent Place\n" "TX 78660\n" "(30.443807, -97.651466)\"\n" "\"4704 Sunridge Ct\n" "TX 78741\n" "(30.219579, -97.727328)\"\n" "\"5931 Cape Coral Dr\n" "TX 78746\n" "(30.278937, -97.836048)\"\n" "\"2815 Oak Ridge Dr\n" "TX 78669\n" "(30.368907, -98.036141)\"\n" "\"8701 Bluffstone Cv. #2202\n" "TX 78759\n" "(30.389267, -97.766356)\"\n" "\"20608 Ed Acklin Rd\n" "TX 78653\n" "(30.27633, -97.49126)\"\n" "\"11824 Morning View Dr\n" "TX 78617\n" "(30.15396, -97.647841)\"\n" "\"7600 Bloomfield Ave\n" "TX 78745\n" "(30.204901, -97.828946)\"\n" "\"14329 Teacup Ln\n" "TX 78660\n" "(30.418056, -97.636821)\"\n" "\"4809 Clear View Dr\n" "TX 78725\n" "(30.244119, -97.581393)\"\n" "\"11511 Catalonia Dr\n" "TX 78759\n" "(30.410848, -97.739218)\"\n" "\"18300 Belfry Pass\n" "TX 78653\n" "(30.31697, -97.53009)\"\n" "\"705 Texas St\n" "TX 78705\n" "(33.222247, -97.124425)\"\n" "\"12904 Schleicher Trl\n" "TX 78732\n" "(30.381982, -97.893992)\"\n" "\"11929 Rosethorn Dr\n" "TX 78758\n" "(30.400166, -97.700383)\"\n" "\"2520 East 3rd St\n" "TX 78702\n" "(30.255743, -97.714709)\"\n" "\"11305 Cezanne St\n" "TX 78726\n" "(30.44945, -97.820962)\"\n" "\"5336 Magdelena Dr\n" "TX 78704\n" "(30.257704, -97.833415)\"\n" "\"2401 Cecil Dr\n" "TX 78744\n" "(30.165036, -97.773046)\"\n" "\"5205 Bantom Woods Bnd.\n" "TX 78721\n" "(30.273542, -97.631229)\"\n" "\"2401 Cecil Dr\n" "TX 78744\n" "(30.165036, -97.773046)\"\n" "\"2718 Jorwoods Dr\n" "TX 78745\n" "(30.201176, -97.821866)\"\n" "\"7200 Reaburn St.\n" "TX 78749\n" "(30.213462, -97.836052)\"\n" "\"6204 Skahan Ln.\n" "TX 78739\n" "(30.187183, -97.892496)\"\n" "\"905 Tudor House Road\n" "TX 78660\n" "(30.421455, -97.640466)\"\n" "\"1205 Quail Park Dr\n" "TX 78758\n" "(30.365438, -97.706068)\"\n" "\"6204 Skahan Ln.\n" "TX 78739\n" "(30.187183, -97.892496)\"\n" "\"7002 Montana St\n" "TX 78741\n" "(30.228851, -97.691627)\"\n" "\"3703 Grayson Ln\n" "TX 78722\n" "(30.288239, -97.708983)\"\n" "\"1302 Canyon Edge Dr\n" "TX 78733\n" "(30.336045, -97.864337)\"\n" "\"11824 Morning View Dr\n" "TX 78617\n" "(30.15396, -97.647841)\"\n" "\"4707 Carsonhill Dr\n" "TX 78723\n" "(30.288236, -97.676578)\"\n" "\"1411 Justin Ln\n" "TX 78757\n" "(30.341012, -97.727488)\"\n" "\"6319 Parliament Dr. #A\n" "TX 78724\n" "(30.286891, -97.658975)\"\n" "\"5205 Bantom Woods Bnd.\n" "TX 78721\n" "(30.273542, -97.631229)\"\n" "\"1304 Neans Dr.\n" "TX 78758\n" "(30.376535, -97.700762)\"\n" "\"7701 Callbram Ln\n" "TX 78736\n" "(30.233294, -97.892511)\"\n" "\"14329 Teacup Ln\n" "TX 78660\n" "(30.418056, -97.636821)\"\n" "\"14028 Lakeview Dr\n" "TX 78732\n" "(30.414976, -97.89322)\"\n" "\"5107 Saddle Cir.\n" "TX 78727\n" "(30.422686, -97.733608)\"\n" "\"1302 Lipan Trl\n" "TX 78733\n" "(30.33921, -97.870528)\"\n" "\"11511 Catalonia Dr\n" "TX 78759\n" "(30.410848, -97.739218)\"\n" "\"14707 Reynero Ln. #E\n" "TX 78617\n" "(30.089307, -97.64347)\"\n" "\"3705 Robinson Ave.\n" "TX 78722\n" "(30.293536, -97.719088)\"\n" "\"412 Summer Alcove Way\n" "TX 78732\n" "(30.340744, -97.912968)\"\n" "\"7200 Reaburn St.\n" "TX 78749\n" "(30.213462, -97.836052)\"\n" "\"7201 Levander Loop\n" "TX 78702\n" "(30.251079, -97.691727)\"\n" "\"2401 Emmett Pkwy\n" "TX 78728\n" "(30.452414, -97.677731)\"\n" "\"6319 Parliament Dr. #A\n" "TX 78724\n" "(30.286891, -97.658975)\"\n" "\"1910 Haskell St.\n" "TX 78722\n" "(30.252278, -97.725848)\"\n" "\"2813 Tradewind Dr.\n" "TX 78669\n" "(30.362084, -98.024851)\"\n" "\"7916 Adelaide Dr\n" "TX 78739\n" "(30.19158, -97.919402)\"\n" "\"903 Vincent Place\n" "TX 78660\n" "(30.443807, -97.651466)\"\n" "\"4812 Candletree Ln\n" "TX 78744\n" "(30.188398, -97.74624)\"\n" "\"6604 Jamaica Ct\n" "TX 78757\n" "(30.347375, -97.748886)\"") subst = "\\1\\t\\2" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0, re.MULTILINE) if result: print (result) # 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