@@ -96,19 +96,22 @@ the expression ``(?:a{6})*`` matches any multiple of six ``'a'`` characters.
9696
9797The special characters are:
9898
99+ .. _syntax-dot :
99100.. index :: single: . (dot); in regular expressions
100101
101102``. ``
102103 (Dot.) In the default mode, this matches any character except a newline. If
103104 the :const: `DOTALL ` flag has been specified, this matches any character
104105 including a newline.
105106
107+ .. _syntax-caret :
106108.. index :: single: ^ (caret); in regular expressions
107109
108110``^ ``
109111 (Caret.) Matches the start of the string, and in :const: `MULTILINE ` mode also
110112 matches immediately after each newline.
111113
114+ .. _syntax-dollar :
112115.. index :: single: $ (dollar); in regular expressions
113116
114117``$ ``
@@ -120,26 +123,30 @@ The special characters are:
120123 a single ``$ `` in ``'foo\n' `` will find two (empty) matches: one just before
121124 the newline, and one at the end of the string.
122125
126+ .. _syntax-asterisk :
123127.. index :: single: * (asterisk); in regular expressions
124128
125129``* ``
126130 Causes the resulting RE to match 0 or more repetitions of the preceding RE, as
127131 many repetitions as are possible. ``ab* `` will match 'a', 'ab', or 'a' followed
128132 by any number of 'b's.
129133
134+ .. _syntax-plus :
130135.. index :: single: + (plus); in regular expressions
131136
132137``+ ``
133138 Causes the resulting RE to match 1 or more repetitions of the preceding RE.
134139 ``ab+ `` will match 'a' followed by any non-zero number of 'b's; it will not
135140 match just 'a'.
136141
142+ .. _syntax-question-mark :
137143.. index :: single: ? (question mark); in regular expressions
138144
139145``? ``
140146 Causes the resulting RE to match 0 or 1 repetitions of the preceding RE.
141147 ``ab? `` will match either 'a' or 'ab'.
142148
149+ .. _syntax-non-greedy :
143150.. index ::
144151 single: *?; in regular expressions
145152 single: +?; in regular expressions
@@ -154,6 +161,7 @@ The special characters are:
154161 characters as possible will be matched. Using the RE ``<.*?> `` will match
155162 only ``'<a>' ``.
156163
164+ .. _syntax-curly-brackets :
157165.. index ::
158166 single: {} (curly brackets); in regular expressions
159167
@@ -178,6 +186,7 @@ The special characters are:
178186 6-character string ``'aaaaaa' ``, ``a{3,5} `` will match 5 ``'a' `` characters,
179187 while ``a{3,5}? `` will only match 3 characters.
180188
189+ .. _syntax-backslash :
181190.. index :: single: \ (backslash); in regular expressions
182191
183192``\ ``
@@ -193,6 +202,7 @@ The special characters are:
193202 is complicated and hard to understand, so it's highly recommended that you use
194203 raw strings for all but the simplest expressions.
195204
205+ .. _syntax-square-brackets :
196206.. index ::
197207 single: [] (square brackets); in regular expressions
198208
@@ -253,6 +263,7 @@ The special characters are:
253263 :exc: `FutureWarning ` is raised if a character set contains constructs
254264 that will change semantically in the future.
255265
266+ .. _syntax-vertical-bar :
256267.. index :: single: | (vertical bar); in regular expressions
257268
258269``| ``
@@ -266,6 +277,7 @@ The special characters are:
266277 greedy. To match a literal ``'|' ``, use ``\| ``, or enclose it inside a
267278 character class, as in ``[|] ``.
268279
280+ .. _syntax-parentheses :
269281.. index ::
270282 single: () (parentheses); in regular expressions
271283
@@ -276,6 +288,7 @@ The special characters are:
276288 special sequence, described below. To match the literals ``'(' `` or ``')' ``,
277289 use ``\( `` or ``\) ``, or enclose them inside a character class: ``[(] ``, ``[)] ``.
278290
291+ .. _syntax-extension :
279292.. index :: single: (?; in regular expressions
280293
281294``(?...) ``
@@ -285,6 +298,8 @@ The special characters are:
285298 group; ``(?P<name>...) `` is the only exception to this rule. Following are the
286299 currently supported extensions.
287300
301+ .. _syntax-inline-flags :
302+
288303``(?aiLmsux) ``
289304 (One or more letters from the set ``'a' ``, ``'i' ``, ``'L' ``, ``'m' ``,
290305 ``'s' ``, ``'u' ``, ``'x' ``.) The group matches the empty string; the
@@ -299,6 +314,7 @@ The special characters are:
299314 :func: `re.compile ` function. Flags should be used first in the
300315 expression string.
301316
317+ .. _syntax-non-capturing :
302318.. index :: single: (?:; in regular expressions
303319
304320``(?:...) ``
@@ -307,6 +323,8 @@ The special characters are:
307323 *cannot * be retrieved after performing a match or referenced later in the
308324 pattern.
309325
326+ .. _syntax-inline-flags-group :
327+
310328``(?aiLmsux-imsx:...) ``
311329 (Zero or more letters from the set ``'a' ``, ``'i' ``, ``'L' ``, ``'m' ``,
312330 ``'s' ``, ``'u' ``, ``'x' ``, optionally followed by ``'-' `` followed by
@@ -333,6 +351,7 @@ The special characters are:
333351 .. versionchanged :: 3.7
334352 The letters ``'a' ``, ``'L' `` and ``'u' `` also can be used in a group.
335353
354+ .. _syntax-named-capture :
336355.. index :: single: (?P<; in regular expressions
337356
338357``(?P<name>...) ``
@@ -360,31 +379,36 @@ The special characters are:
360379 | | * ``\1 `` |
361380 +---------------------------------------+----------------------------------+
362381
382+ .. _syntax-named-backreference :
363383.. index :: single: (?P=; in regular expressions
364384
365385``(?P=name) ``
366386 A backreference to a named group; it matches whatever text was matched by the
367387 earlier group named *name *.
368388
389+ .. _syntax-comment :
369390.. index :: single: (?#; in regular expressions
370391
371392``(?#...) ``
372393 A comment; the contents of the parentheses are simply ignored.
373394
395+ .. _syntax-lookahead :
374396.. index :: single: (?=; in regular expressions
375397
376398``(?=...) ``
377399 Matches if ``... `` matches next, but doesn't consume any of the string. This is
378400 called a :dfn: `lookahead assertion `. For example, ``Isaac (?=Asimov) `` will match
379401 ``'Isaac ' `` only if it's followed by ``'Asimov' ``.
380402
403+ .. _syntax-negative-lookahead :
381404.. index :: single: (?!; in regular expressions
382405
383406``(?!...) ``
384407 Matches if ``... `` doesn't match next. This is a :dfn: `negative lookahead assertion `.
385408 For example, ``Isaac (?!Asimov) `` will match ``'Isaac ' `` only if it's *not *
386409 followed by ``'Asimov' ``.
387410
411+ .. _syntax-lookbehind :
388412.. index :: single: (?<=; in regular expressions
389413
390414``(?<=...) ``
@@ -412,6 +436,7 @@ The special characters are:
412436 .. versionchanged :: 3.5
413437 Added support for group references of fixed length.
414438
439+ .. _syntax-negative-lookbehind :
415440.. index :: single: (?<!; in regular expressions
416441
417442``(?<!...) ``
@@ -421,6 +446,8 @@ The special characters are:
421446 some fixed length. Patterns which start with negative lookbehind assertions may
422447 match at the beginning of the string being searched.
423448
449+ .. _syntax-yes-no-pattern :
450+
424451``(?(id/name)yes-pattern|no-pattern) ``
425452 Will try to match with ``yes-pattern `` if the group with given *id * or
426453 *name * exists, and with ``no-pattern `` if it doesn't. ``no-pattern `` is
@@ -435,6 +462,7 @@ If the ordinary character is not an ASCII digit or an ASCII letter, then the
435462resulting RE will match the second character. For example, ``\$ `` matches the
436463character ``'$' ``.
437464
465+ .. _syntax-special-number :
438466.. index :: single: \ (backslash); in regular expressions
439467
440468``\number ``
@@ -447,11 +475,13 @@ character ``'$'``.
447475 ``'[' `` and ``']' `` of a character class, all numeric escapes are treated as
448476 characters.
449477
478+ .. _syntax-special-uppercase-A :
450479.. index :: single: \A; in regular expressions
451480
452481``\A ``
453482 Matches only at the start of the string.
454483
484+ .. _syntax-special-b :
455485.. index :: single: \b; in regular expressions
456486
457487``\b ``
@@ -468,6 +498,7 @@ character ``'$'``.
468498 Inside a character range, ``\b `` represents the backspace character, for
469499 compatibility with Python's string literals.
470500
501+ .. _syntax-special-uppercase-B :
471502.. index :: single: \B; in regular expressions
472503
473504``\B ``
@@ -479,6 +510,7 @@ character ``'$'``.
479510 be changed by using the :const: `ASCII ` flag. Word boundaries are
480511 determined by the current locale if the :const: `LOCALE ` flag is used.
481512
513+ .. _syntax-special-d :
482514.. index :: single: \d; in regular expressions
483515
484516``\d ``
@@ -491,13 +523,15 @@ character ``'$'``.
491523 For 8-bit (bytes) patterns:
492524 Matches any decimal digit; this is equivalent to ``[0-9] ``.
493525
526+ .. _syntax-special-uppercase-D :
494527.. index :: single: \D; in regular expressions
495528
496529``\D ``
497530 Matches any character which is not a decimal digit. This is
498531 the opposite of ``\d ``. If the :const: `ASCII ` flag is used this
499532 becomes the equivalent of ``[^0-9] ``.
500533
534+ .. _syntax-special-s :
501535.. index :: single: \s; in regular expressions
502536
503537``\s ``
@@ -512,13 +546,15 @@ character ``'$'``.
512546 Matches characters considered whitespace in the ASCII character set;
513547 this is equivalent to ``[ \t\n\r\f\v] ``.
514548
549+ .. _syntax-special-uppercase-S :
515550.. index :: single: \S; in regular expressions
516551
517552``\S ``
518553 Matches any character which is not a whitespace character. This is
519554 the opposite of ``\s ``. If the :const: `ASCII ` flag is used this
520555 becomes the equivalent of ``[^ \t\n\r\f\v] ``.
521556
557+ .. _syntax-special-w :
522558.. index :: single: \w; in regular expressions
523559
524560``\w ``
@@ -534,6 +570,7 @@ character ``'$'``.
534570 used, matches characters considered alphanumeric in the current locale
535571 and the underscore.
536572
573+ .. _syntax-special-uppercase-W :
537574.. index :: single: \W; in regular expressions
538575
539576``\W ``
@@ -543,11 +580,13 @@ character ``'$'``.
543580 used, matches characters which are neither alphanumeric in the current locale
544581 nor the underscore.
545582
583+ .. _syntax-special-uppercase-Z :
546584.. index :: single: \Z; in regular expressions
547585
548586``\Z ``
549587 Matches only at the end of the string.
550588
589+ .. _syntax-special-py :
551590.. index ::
552591 single: \a ; in regular expressions
553592 single: \b ; in regular expressions
0 commit comments