Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Fork Regex
    ctrl+s
  • Add to Community Library

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"^.*name=\"(?!Polyline\d{3}).*" test_str = ("</polyline_object><polyline_object name=\"ECC018\" kind=\"PolyLineObjectX\"><name>ECC018</name><point length=\"3\"> -312.52499389648435 62.385520935058598 39.511650085449216 </point><point length=\"3\"> -309.38851928710938 62.611492156982426 39.349102020263674 </point>\n" " </polyline_object><polyline_object name=\"STEP (25)\" kind=\"PolyLineObjectX\"><name>STEP (25)</name><point length=\"3\"> -313.64254760742189 62.275627136230464 39.640590667724608 </point><point length=\"3\"> -312.55957031249997 62.376560211181645 39.627662658691405 </point><point length=\"3\"> -312.7188415527344 64.059944152832026 39.638328552246093 </point><point length=\"3\"> -313.1711730957031 64.028800964355469 39.651771545410157 </point>\n" " </polyline_object><polyline_object name=\"Polyline000 (3)\" kind=\"PolyLineObjectX\"><name>Polyline000 (3)</name><point length=\"3\"> 2.6950883865356445 44.503276824951174 37.697837829589843 </point><point length=\"3\"> -75.466423034667968 47.88733673095703 39.203029632568358 </point><point length=\"3\"> -111.57073211669922 43.517368316650394 39.25448226928711 </point><point length=\"3\"> -118.22566986083984 37.122959136962893 39.077449798583987 </point><point length=\"3\"> -122.02384185791014 27.188623428344726 38.753135681152346 </point><point length=\"3\"> -121.8035888671875 22.215513229370118 38.595668792724608 </point><point length=\"3\"> -120.69635772705078 10.44062900543213 38.525798797607424 </point><point length=\"3\"> -119.39793395996093 -1.391708493232727 38.479351043701171 </point><point length=\"3\"> -111.05265045166016 -0.50858658552169798 38.464771270751955 </point><point length=\"3\"> -109.4428482055664 -13.537007331848144 38.171108245849606 </point>\n" " </polyline_object><polyline_object name=\"Polyline001 (3)\" kind=\"PolyLineObjectX\"><name>Polyline001 (3)</name><point length=\"3\"> -129.52786254882813 166.05583190917968 40.779067993164064 </point><point length=\"3\"> -125.67138671875 156.94186401367187 40.774162292480467 </point><point length=\"3\"> -113.06429290771485 116.86449432373046 40.768569946289062 </point><point length=\"3\"> -113.13454437255859 116.2726516723633 38.973728179931642 </point><point length=\"3\"> -112.24276733398437 113.77603149414062 38.96575927734375 </point><point length=\"3\"> -111.49858856201173 114.01608276367187 38.981853485107424 </point><point length=\"3\"> -106.42765045166016 100.83160400390626 39.037631988525389 </point><point length=\"3\"> -107.75248718261718 99.620536804199219 38.996852874755859 </point><point length=\"3\"> -103.67796325683594 86.614151000976563 39.067848205566406 </point><point length=\"3\"> -116.04350280761718 74.861045837402342 39.25809097290039 </point><point length=\"3\"> -122.38642120361328 74.47401428222656 39.252414703369139 </point><point length=\"3\"> -122.78543853759765 74.44397735595703 39.25035858154297 </point><point length=\"3\"> -122.8647918701172 73.826538085937498 42.272285461425779 </point><point length=\"3\"> -119.59778594970704 41.25065612792969 42.267509460449216 </point><point length=\"3\"> -175.69285583496093 35.908145904541018 42.259567260742189 </point><point length=\"3\"> -188.11454772949219 63.682300567626957 42.2263069152832 </point><point length=\"3\"> -218.66964721679686 60.854137420654298 42.268066406249997 </point><point length=\"3\"> -221.23516845703126 88.376388549804685 41.072391510009766 </point><point length=\"3\"> -225.47735595703126 88.032569885253901 41.053840637207034 </point><point length=\"3\"> -229.76127624511718 131.20693969726563 40.885227203369139 </point><point length=\"3\"> -187.65846252441405 152.36131286621094 40.93291473388672 </point><point length=\"3\"> -180.48707580566406 149.78179931640624 40.9343147277832 </point><point length=\"3\"> -129.52786254882813 166.05583190917968 40.779067993164064 </point>\n" " </polyline_object><polyline_object name=\"Polyline002 (3)\" kind=\"PolyLineObjectX\"><name>Polyline002 (3)</name><point length=\"3\"> -112.50492858886718 115.78641510009766 38.953884124755859 </point><point length=\"3\"> -111.31856536865234 112.05601501464843 38.973159790039066 </point>") 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