Skip to content

Commit c6cd3cc

Browse files
bpo-47081: Replace "qualifiers" with "quantifiers" in the re module documentation (GH-32028)
It is a more commonly used term.
1 parent 4f97d64 commit c6cd3cc

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

Doc/howto/regex.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ while ``+`` requires at least *one* occurrence. To use a similar example,
230230
``ca+t`` will match ``'cat'`` (1 ``'a'``), ``'caaat'`` (3 ``'a'``\ s), but won't
231231
match ``'ct'``.
232232

233-
There are two more repeating qualifiers. The question mark character, ``?``,
233+
There are two more repeating operators or quantifiers. The question mark character, ``?``,
234234
matches either once or zero times; you can think of it as marking something as
235235
being optional. For example, ``home-?brew`` matches either ``'homebrew'`` or
236236
``'home-brew'``.
237237

238-
The most complicated repeated qualifier is ``{m,n}``, where *m* and *n* are
239-
decimal integers. This qualifier means there must be at least *m* repetitions,
238+
The most complicated quantifier is ``{m,n}``, where *m* and *n* are
239+
decimal integers. This quantifier means there must be at least *m* repetitions,
240240
and at most *n*. For example, ``a/{1,3}b`` will match ``'a/b'``, ``'a//b'``, and
241241
``'a///b'``. It won't match ``'ab'``, which has no slashes, or ``'a////b'``, which
242242
has four.
@@ -245,7 +245,7 @@ You can omit either *m* or *n*; in that case, a reasonable value is assumed for
245245
the missing value. Omitting *m* is interpreted as a lower limit of 0, while
246246
omitting *n* results in an upper bound of infinity.
247247

248-
Readers of a reductionist bent may notice that the three other qualifiers can
248+
Readers of a reductionist bent may notice that the three other quantifiers can
249249
all be expressed using this notation. ``{0,}`` is the same as ``*``, ``{1,}``
250250
is equivalent to ``+``, and ``{0,1}`` is the same as ``?``. It's better to use
251251
``*``, ``+``, or ``?`` when you can, simply because they're shorter and easier
@@ -803,7 +803,7 @@ which matches the header's value.
803803
Groups are marked by the ``'('``, ``')'`` metacharacters. ``'('`` and ``')'``
804804
have much the same meaning as they do in mathematical expressions; they group
805805
together the expressions contained inside them, and you can repeat the contents
806-
of a group with a repeating qualifier, such as ``*``, ``+``, ``?``, or
806+
of a group with a quantifier, such as ``*``, ``+``, ``?``, or
807807
``{m,n}``. For example, ``(ab)*`` will match zero or more repetitions of
808808
``ab``. ::
809809

@@ -1326,7 +1326,7 @@ backtrack character by character until it finds a match for the ``>``. The
13261326
final match extends from the ``'<'`` in ``'<html>'`` to the ``'>'`` in
13271327
``'</title>'``, which isn't what you want.
13281328

1329-
In this case, the solution is to use the non-greedy qualifiers ``*?``, ``+?``,
1329+
In this case, the solution is to use the non-greedy quantifiers ``*?``, ``+?``,
13301330
``??``, or ``{m,n}?``, which match as *little* text as possible. In the above
13311331
example, the ``'>'`` is tried immediately after the first ``'<'`` matches, and
13321332
when it fails, the engine advances a character at a time, retrying the ``'>'``

Doc/library/re.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Some characters, like ``'|'`` or ``'('``, are special. Special
8787
characters either stand for classes of ordinary characters, or affect
8888
how the regular expressions around them are interpreted.
8989

90-
Repetition qualifiers (``*``, ``+``, ``?``, ``{m,n}``, etc) cannot be
90+
Repetition operators or quantifiers (``*``, ``+``, ``?``, ``{m,n}``, etc) cannot be
9191
directly nested. This avoids ambiguity with the non-greedy modifier suffix
9292
``?``, and with other modifiers in other implementations. To apply a second
9393
repetition to an inner repetition, parentheses may be used. For example,
@@ -146,10 +146,10 @@ The special characters are:
146146
single: ??; in regular expressions
147147
148148
``*?``, ``+?``, ``??``
149-
The ``'*'``, ``'+'``, and ``'?'`` qualifiers are all :dfn:`greedy`; they match
149+
The ``'*'``, ``'+'``, and ``'?'`` quantifiers are all :dfn:`greedy`; they match
150150
as much text as possible. Sometimes this behaviour isn't desired; if the RE
151151
``<.*>`` is matched against ``'<a> b <c>'``, it will match the entire
152-
string, and not just ``'<a>'``. Adding ``?`` after the qualifier makes it
152+
string, and not just ``'<a>'``. Adding ``?`` after the quantifier makes it
153153
perform the match in :dfn:`non-greedy` or :dfn:`minimal` fashion; as *few*
154154
characters as possible will be matched. Using the RE ``<.*?>`` will match
155155
only ``'<a>'``.
@@ -160,11 +160,11 @@ The special characters are:
160160
single: ?+; in regular expressions
161161
162162
``*+``, ``++``, ``?+``
163-
Like the ``'*'``, ``'+'``, and ``'?'`` qualifiers, those where ``'+'`` is
163+
Like the ``'*'``, ``'+'``, and ``'?'`` quantifiers, those where ``'+'`` is
164164
appended also match as many times as possible.
165-
However, unlike the true greedy qualifiers, these do not allow
165+
However, unlike the true greedy quantifiers, these do not allow
166166
back-tracking when the expression following it fails to match.
167-
These are known as :dfn:`possessive` qualifiers.
167+
These are known as :dfn:`possessive` quantifiers.
168168
For example, ``a*a`` will match ``'aaaa'`` because the ``a*`` will match
169169
all 4 ``'a'``s, but, when the final ``'a'`` is encountered, the
170170
expression is backtracked so that in the end the ``a*`` ends up matching
@@ -198,15 +198,15 @@ The special characters are:
198198
``{m,n}?``
199199
Causes the resulting RE to match from *m* to *n* repetitions of the preceding
200200
RE, attempting to match as *few* repetitions as possible. This is the
201-
non-greedy version of the previous qualifier. For example, on the
201+
non-greedy version of the previous quantifier. For example, on the
202202
6-character string ``'aaaaaa'``, ``a{3,5}`` will match 5 ``'a'`` characters,
203203
while ``a{3,5}?`` will only match 3 characters.
204204

205205
``{m,n}+``
206206
Causes the resulting RE to match from *m* to *n* repetitions of the
207207
preceding RE, attempting to match as many repetitions as possible
208208
*without* establishing any backtracking points.
209-
This is the possessive version of the qualifier above.
209+
This is the possessive version of the quantifier above.
210210
For example, on the 6-character string ``'aaaaaa'``, ``a{3,5}+aa``
211211
attempt to match 5 ``'a'`` characters, then, requiring 2 more ``'a'``s,
212212
will need more characters than available and thus fail, while

Doc/whatsnew/3.11.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ os
298298
re
299299
--
300300

301-
* Atomic grouping (``(?>...)``) and possessive qualifiers (``*+``, ``++``,
301+
* Atomic grouping (``(?>...)``) and possessive quantifiers (``*+``, ``++``,
302302
``?+``, ``{m,n}+``) are now supported in regular expressions.
303303
(Contributed by Jeffrey C. Jacobs and Serhiy Storchaka in :issue:`433030`.)
304304

Lib/test/test_re.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,9 +2038,9 @@ def test_bug_40736(self):
20382038
with self.assertRaisesRegex(TypeError, "got 'type'"):
20392039
re.search("x*", type)
20402040

2041-
def test_possessive_qualifiers(self):
2042-
"""Test Possessive Qualifiers
2043-
Test qualifiers of the form @+ for some repetition operator @,
2041+
def test_possessive_quantifiers(self):
2042+
"""Test Possessive Quantifiers
2043+
Test quantifiers of the form @+ for some repetition operator @,
20442044
e.g. x{3,5}+ meaning match from 3 to 5 greadily and proceed
20452045
without creating a stack frame for rolling the stack back and
20462046
trying 1 or more fewer matches."""
@@ -2077,7 +2077,7 @@ def test_possessive_qualifiers(self):
20772077
self.assertIsNone(re.match("^x{}+$", "xxx"))
20782078
self.assertTrue(re.match("^x{}+$", "x{}"))
20792079

2080-
def test_fullmatch_possessive_qualifiers(self):
2080+
def test_fullmatch_possessive_quantifiers(self):
20812081
self.assertTrue(re.fullmatch(r'a++', 'a'))
20822082
self.assertTrue(re.fullmatch(r'a*+', 'a'))
20832083
self.assertTrue(re.fullmatch(r'a?+', 'a'))
@@ -2096,7 +2096,7 @@ def test_fullmatch_possessive_qualifiers(self):
20962096
self.assertIsNone(re.fullmatch(r'(?:ab)?+', 'abc'))
20972097
self.assertIsNone(re.fullmatch(r'(?:ab){1,3}+', 'abc'))
20982098

2099-
def test_findall_possessive_qualifiers(self):
2099+
def test_findall_possessive_quantifiers(self):
21002100
self.assertEqual(re.findall(r'a++', 'aab'), ['aa'])
21012101
self.assertEqual(re.findall(r'a*+', 'aab'), ['aa', '', ''])
21022102
self.assertEqual(re.findall(r'a?+', 'aab'), ['a', 'a', '', ''])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add support of atomic grouping (``(?>...)``) and possessive qualifiers
1+
Add support of atomic grouping (``(?>...)``) and possessive quantifiers
22
(``*+``, ``++``, ``?+``, ``{m,n}+``) in :mod:`regular expressions <re>`.

0 commit comments

Comments
 (0)