@@ -245,16 +245,32 @@ The special characters are:
245245 *cannot * be retrieved after performing a match or referenced later in the
246246 pattern.
247247
248- ``(?imsx-imsx:...) ``
249- (Zero or more letters from the set ``'i' ``, ``'m' ``, ``'s' ``, ``'x' ``,
250- optionally followed by ``'-' `` followed by one or more letters from the
251- same set.) The letters set or removes the corresponding flags:
252- :const: `re.I ` (ignore case), :const: `re.M ` (multi-line), :const: `re.S `
253- (dot matches all), and :const: `re.X ` (verbose), for the part of the
254- expression. (The flags are described in :ref: `contents-of-module-re `.)
248+ ``(?aiLmsux-imsx:...) ``
249+ (Zero or more letters from the set ``'a' ``, ``'i' ``, ``'L' ``, ``'m' ``,
250+ ``'s' ``, ``'u' ``, ``'x' ``, optionally followed by ``'-' `` followed by
251+ one or more letters from the ``'i' ``, ``'m' ``, ``'s' ``, ``'x' ``.)
252+ The letters set or remove the corresponding flags:
253+ :const: `re.A ` (ASCII-only matching), :const: `re.I ` (ignore case),
254+ :const: `re.L ` (locale dependent), :const: `re.M ` (multi-line),
255+ :const: `re.S ` (dot matches all), :const: `re.U ` (Unicode matching),
256+ and :const: `re.X ` (verbose), for the part of the expression.
257+ (The flags are described in :ref: `contents-of-module-re `.)
258+
259+ The letters ``'a' ``, ``'L' `` and ``'u' `` are mutually exclusive when used
260+ as inline flags, so they can't be combined or follow ``'-' ``. Instead,
261+ when one of them appears in an inline group, it overrides the matching mode
262+ in the enclosing group. In Unicode patterns ``(?a:...) `` switches to
263+ ASCII-only matching, and ``(?u:...) `` switches to Unicode matching
264+ (default). In byte pattern ``(?L:...) `` switches to locale depending
265+ matching, and ``(?a:...) `` switches to ASCII-only matching (default).
266+ This override is only in effect for the narrow inline group, and the
267+ original matching mode is restored outside of the group.
255268
256269 .. versionadded :: 3.6
257270
271+ .. versionchanged :: 3.7
272+ The letters ``'a' ``, ``'L' `` and ``'u' `` also can be used in a group.
273+
258274``(?P<name>...) ``
259275 Similar to regular parentheses, but the substring matched by the group is
260276 accessible via the symbolic group name *name *. Group names must be valid
@@ -384,29 +400,23 @@ character ``'$'``.
384400 Matches any Unicode decimal digit (that is, any character in
385401 Unicode character category [Nd]). This includes ``[0-9] ``, and
386402 also many other digit characters. If the :const: `ASCII ` flag is
387- used only ``[0-9] `` is matched (but the flag affects the entire
388- regular expression, so in such cases using an explicit ``[0-9] ``
389- may be a better choice).
403+ used only ``[0-9] `` is matched.
390404
391405 For 8-bit (bytes) patterns:
392406 Matches any decimal digit; this is equivalent to ``[0-9] ``.
393407
394408``\D ``
395409 Matches any character which is not a decimal digit. This is
396410 the opposite of ``\d ``. If the :const: `ASCII ` flag is used this
397- becomes the equivalent of ``[^0-9] `` (but the flag affects the entire
398- regular expression, so in such cases using an explicit ``[^0-9] `` may
399- be a better choice).
411+ becomes the equivalent of ``[^0-9] ``.
400412
401413``\s ``
402414 For Unicode (str) patterns:
403415 Matches Unicode whitespace characters (which includes
404416 ``[ \t\n\r\f\v] ``, and also many other characters, for example the
405417 non-breaking spaces mandated by typography rules in many
406418 languages). If the :const: `ASCII ` flag is used, only
407- ``[ \t\n\r\f\v] `` is matched (but the flag affects the entire
408- regular expression, so in such cases using an explicit
409- ``[ \t\n\r\f\v] `` may be a better choice).
419+ ``[ \t\n\r\f\v] `` is matched.
410420
411421 For 8-bit (bytes) patterns:
412422 Matches characters considered whitespace in the ASCII character set;
@@ -415,18 +425,14 @@ character ``'$'``.
415425``\S ``
416426 Matches any character which is not a whitespace character. This is
417427 the opposite of ``\s ``. If the :const: `ASCII ` flag is used this
418- becomes the equivalent of ``[^ \t\n\r\f\v] `` (but the flag affects the entire
419- regular expression, so in such cases using an explicit ``[^ \t\n\r\f\v] `` may
420- be a better choice).
428+ becomes the equivalent of ``[^ \t\n\r\f\v] ``.
421429
422430``\w ``
423431 For Unicode (str) patterns:
424432 Matches Unicode word characters; this includes most characters
425433 that can be part of a word in any language, as well as numbers and
426434 the underscore. If the :const: `ASCII ` flag is used, only
427- ``[a-zA-Z0-9_] `` is matched (but the flag affects the entire
428- regular expression, so in such cases using an explicit
429- ``[a-zA-Z0-9_] `` may be a better choice).
435+ ``[a-zA-Z0-9_] `` is matched.
430436
431437 For 8-bit (bytes) patterns:
432438 Matches characters considered alphanumeric in the ASCII character set;
@@ -437,9 +443,7 @@ character ``'$'``.
437443``\W ``
438444 Matches any character which is not a word character. This is
439445 the opposite of ``\w ``. If the :const: `ASCII ` flag is used this
440- becomes the equivalent of ``[^a-zA-Z0-9_] `` (but the flag affects the
441- entire regular expression, so in such cases using an explicit
442- ``[^a-zA-Z0-9_] `` may be a better choice). If the :const: `LOCALE ` flag is
446+ becomes the equivalent of ``[^a-zA-Z0-9_] ``. If the :const: `LOCALE ` flag is
443447 used, matches characters considered alphanumeric in the current locale
444448 and the underscore.
445449
@@ -563,9 +567,7 @@ form.
563567 letter I with dot above), 'ı' (U+0131, Latin small letter dotless i),
564568 'ſ' (U+017F, Latin small letter long s) and 'K' (U+212A, Kelvin sign).
565569 If the :const: `ASCII ` flag is used, only letters 'a' to 'z'
566- and 'A' to 'Z' are matched (but the flag affects the entire regular
567- expression, so in such cases using an explicit ``(?-i:[a-zA-Z]) `` may be
568- a better choice).
570+ and 'A' to 'Z' are matched.
569571
570572.. data :: L
571573 LOCALE
0 commit comments