You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -10198,15 +10198,15 @@ no VAL is specified, the key will be given the value true.</p>
10198
10198
<blockquote>
10199
10199
<p>A regular expression (or RE) specifies a set of strings that matches it; the functions in this module let you check if a particular string matches a given regular expression</p>
10200
10200
</blockquote>
10201
-
<p>This blog post gives an overview and examples of regular expression syntax as implemented by the <code>re</code> built-in module (Python 3.11+). Assume ASCII character set unless otherwise specified. This post is an excerpt from my <a href="https://github.com/learnbyexample/py_regular_expressions">Understanding Python re(gex)?</a> book.</p>
10201
+
<p>This blog post gives an overview and examples of regular expression syntax as implemented by the <code>re</code> built-in module (Python 3.13+). Assume ASCII character set unless otherwise specified. This post is an excerpt from my <a href="https://github.com/learnbyexample/py_regular_expressions">Understanding Python re(gex)?</a> book.</p>
10202
10202
<br>
10203
10203
<h2 id="elements-that-define-a-regular-expression">Elements that define a regular expression<a class="zola-anchor" href="#elements-that-define-a-regular-expression" aria-label="Anchor link for: elements-that-define-a-regular-expression">🔗</a></h2>
<tr><td><code>\A</code></td><td>restricts the match to the start of string</td></tr>
10206
10206
<tr><td><code>\Z</code></td><td>restricts the match to the end of string</td></tr>
10207
10207
<tr><td><code>^</code></td><td>restricts the match to the start of line</td></tr>
10208
10208
<tr><td><code>$</code></td><td>restricts the match to the end of line</td></tr>
10209
-
<tr><td><code>\n</code></td><td>newline character is used as line separator</td></tr>
10209
+
<tr><td><code>\n</code></td><td>newline character is used as the line separator</td></tr>
10210
10210
<tr><td><code>re.MULTILINE</code> or <code>re.M</code></td><td>flag to treat input as multiline string</td></tr>
10211
10211
<tr><td><code>\b</code></td><td>restricts the match to the start/end of words</td></tr>
@@ -10243,11 +10243,11 @@ no VAL is specified, the key will be given the value true.</p>
10243
10243
<tr><td><code>[^aeiou]</code></td><td><code>^</code> inverts selection, so this matches any consonant</td></tr>
10244
10244
<tr><td><code>[a-f]</code></td><td><code>-</code> defines a range, so this matches any of abcdef characters</td></tr>
10245
10245
<tr><td><code>\d</code></td><td>Match a digit, same as <code>[0-9]</code></td></tr>
10246
-
<tr><td><code>\D</code></td><td>Match non-digit, same as <code>[^0-9]</code> or <code>[^\d]</code></td></tr>
10247
-
<tr><td><code>\w</code></td><td>Match word character, same as <code>[a-zA-Z0-9_]</code></td></tr>
10248
-
<tr><td><code>\W</code></td><td>Match non-word character, same as <code>[^a-zA-Z0-9_]</code> or <code>[^\w]</code></td></tr>
10249
-
<tr><td><code>\s</code></td><td>Match whitespace character, same as <code>[\ \t\n\r\f\v]</code></td></tr>
10250
-
<tr><td><code>\S</code></td><td>Match non-whitespace character, same as <code>[^\ \t\n\r\f\v]</code> or <code>[^\s]</code></td></tr>
10246
+
<tr><td><code>\D</code></td><td>Match non-digits, same as <code>[^0-9]</code> or <code>[^\d]</code></td></tr>
10247
+
<tr><td><code>\w</code></td><td>Match word characters, same as <code>[a-zA-Z0-9_]</code></td></tr>
10248
+
<tr><td><code>\W</code></td><td>Match non-word characters, same as <code>[^a-zA-Z0-9_]</code> or <code>[^\w]</code></td></tr>
10249
+
<tr><td><code>\s</code></td><td>Match whitespace characters, same as <code>[\ \t\n\r\f\v]</code></td></tr>
10250
+
<tr><td><code>\S</code></td><td>Match non-whitespace characters, same as <code>[^\ \t\n\r\f\v]</code> or <code>[^\s]</code></td></tr>
<tr><td><code>re.IGNORECASE</code> or <code>re.I</code></td><td>flag to ignore case</td></tr>
10266
-
<tr><td><code>re.DOTALL</code> or <code>re.S</code></td><td>allow <code>.</code> metacharacter to match newline character</td></tr>
10266
+
<tr><td><code>re.DOTALL</code> or <code>re.S</code></td><td>allow <code>.</code> metacharacter to match newline characters</td></tr>
10267
10267
<tr><td><code>flags=re.S|re.I</code></td><td>multiple flags can be combined using <code>|</code> operator</td></tr>
10268
10268
<tr><td><code>re.MULTILINE</code> or <code>re.M</code></td><td>allow <code>^</code> and <code>$</code> anchors to match line wise</td></tr>
10269
10269
<tr><td><code>re.VERBOSE</code> or <code>re.X</code></td><td>allows to use literal whitespaces for aligning purposes</td></tr>
@@ -10272,7 +10272,7 @@ no VAL is specified, the key will be given the value true.</p>
10272
10272
<tr><td><code>re.ASCII</code> or <code>re.A</code></td><td>match only ASCII characters for <code>\b</code>, <code>\w</code>, <code>\d</code>, <code>\s</code></td></tr>
10273
10273
<tr><td></td><td>and their opposites, applicable only for Unicode patterns</td></tr>
10274
10274
<tr><td><code>re.LOCALE</code> or <code>re.L</code></td><td>use locale settings for byte patterns and 8-bit locales</td></tr>
10275
-
<tr><td><code>(?#comment)</code></td><td>another way to add comments, not a flag</td></tr>
10275
+
<tr><td><code>(?#comment)</code></td><td>another way to add comments (not a flag)</td></tr>
10276
10276
<tr><td><code>(?flags:pat)</code></td><td>inline flags only for this <code>pat</code>, overrides <code>flags</code> argument</td></tr>
10277
10277
<tr><td></td><td>flags is <code>i</code> for <code>re.I</code>, <code>s</code> for <code>re.S</code>, etc, except <code>L</code> for <code>re.L</code></td></tr>
10278
10278
<tr><td><code>(?-flags:pat)</code></td><td>negate flags only for this <code>pat</code></td></tr>
@@ -10284,17 +10284,17 @@ no VAL is specified, the key will be given the value true.</p>
<tr><td><code>re.Match</code> object</td><td>details like matched portions, location, etc</td></tr>
10286
10286
<tr><td><code>m[0]</code> or <code>m.group(0)</code></td><td>entire matched portion of <code>re.Match</code> object <code>m</code></td></tr>
10287
-
<tr><td><code>m[n]</code> or <code>m.group(n)</code></td><td>matched portion of <em>n</em>th capture group</td></tr>
10287
+
<tr><td><code>m[n]</code> or <code>m.group(n)</code></td><td>matched portion of the <em>n</em>th capture group</td></tr>
10288
10288
<tr><td><code>m.groups()</code></td><td>tuple of all the capture groups' matched portions</td></tr>
10289
-
<tr><td><code>m.span()</code></td><td>start and end+1 index of entire matched portion</td></tr>
10289
+
<tr><td><code>m.span()</code></td><td>start and end+1 index of the entire matched portion</td></tr>
10290
10290
<tr><td></td><td>pass a number to get span of that particular capture group</td></tr>
10291
10291
<tr><td></td><td>can also use <code>m.start()</code> and <code>m.end()</code></td></tr>
10292
-
<tr><td><code>\N</code></td><td>backreference, gives matched portion of <em>N</em>th capture group</td></tr>
10292
+
<tr><td><code>\N</code></td><td>backreference, gives matched portion of the <em>N</em>th capture group</td></tr>
10293
10293
<tr><td></td><td>applies to both search and replacement sections</td></tr>
10294
10294
<tr><td></td><td>possible values: <code>\1</code>, <code>\2</code> up to <code>\99</code> provided no more digits</td></tr>
10295
-
<tr><td><code>\g&lt;N&gt;</code></td><td>backreference, gives matched portion of Nth capture group</td></tr>
10295
+
<tr><td><code>\g&lt;N&gt;</code></td><td>backreference, gives matched portion of the Nth capture group</td></tr>
10296
10296
<tr><td></td><td>possible values: <code>\g&lt;0&gt;</code>, <code>\g&lt;1&gt;</code>, etc (not limited to 99)</td></tr>
10297
-
<tr><td></td><td><code>\g&lt;0&gt;</code> refers to entire matched portion</td></tr>
10297
+
<tr><td></td><td><code>\g&lt;0&gt;</code> refers to the entire matched portion</td></tr>
<tr><td></td><td>refer as <code>'name'</code> in <code>re.Match</code> object</td></tr>
10300
10300
<tr><td></td><td>refer as <code>(?P=name)</code> in search section</td></tr>
@@ -10315,7 +10315,7 @@ no VAL is specified, the key will be given the value true.</p>
10315
10315
<tr><td><code>re.fullmatch</code></td><td>ensures pattern matches the entire input string</td></tr>
10316
10316
<tr><td><code>re.compile</code></td><td>Compile a pattern for reuse, outputs <code>re.Pattern</code> object</td></tr>
10317
10317
<tr><td><code>re.sub</code></td><td>search and replace</td></tr>
10318
-
<tr><td><code>re.sub(r'pat', f, s)</code></td><td>function <code>f</code> with <code>re.Match</code> object as argument</td></tr>
10318
+
<tr><td><code>re.sub(r'pat', f, s)</code></td><td>function <code>f</code> with <code>re.Match</code> object as the argument</td></tr>
10319
10319
<tr><td><code>re.escape</code></td><td>automatically escape all metacharacters</td></tr>
10320
10320
<tr><td><code>re.split</code></td><td>split a string based on RE</td></tr>
10321
10321
<tr><td></td><td>text matched by the groups will be part of the output</td></tr>
@@ -10359,7 +10359,7 @@ no VAL is specified, the key will be given the value true.</p>
0 commit comments