mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-47081: Replace "qualifiers" with "quantifiers" in the re module documentation (GH-32028)
It is a more commonly used term.
This commit is contained in:
parent
4f97d64c83
commit
c6cd3cc93c
5 changed files with 21 additions and 21 deletions
|
@ -230,13 +230,13 @@ while ``+`` requires at least *one* occurrence. To use a similar example,
|
|||
``ca+t`` will match ``'cat'`` (1 ``'a'``), ``'caaat'`` (3 ``'a'``\ s), but won't
|
||||
match ``'ct'``.
|
||||
|
||||
There are two more repeating qualifiers. The question mark character, ``?``,
|
||||
There are two more repeating operators or quantifiers. The question mark character, ``?``,
|
||||
matches either once or zero times; you can think of it as marking something as
|
||||
being optional. For example, ``home-?brew`` matches either ``'homebrew'`` or
|
||||
``'home-brew'``.
|
||||
|
||||
The most complicated repeated qualifier is ``{m,n}``, where *m* and *n* are
|
||||
decimal integers. This qualifier means there must be at least *m* repetitions,
|
||||
The most complicated quantifier is ``{m,n}``, where *m* and *n* are
|
||||
decimal integers. This quantifier means there must be at least *m* repetitions,
|
||||
and at most *n*. For example, ``a/{1,3}b`` will match ``'a/b'``, ``'a//b'``, and
|
||||
``'a///b'``. It won't match ``'ab'``, which has no slashes, or ``'a////b'``, which
|
||||
has four.
|
||||
|
@ -245,7 +245,7 @@ You can omit either *m* or *n*; in that case, a reasonable value is assumed for
|
|||
the missing value. Omitting *m* is interpreted as a lower limit of 0, while
|
||||
omitting *n* results in an upper bound of infinity.
|
||||
|
||||
Readers of a reductionist bent may notice that the three other qualifiers can
|
||||
Readers of a reductionist bent may notice that the three other quantifiers can
|
||||
all be expressed using this notation. ``{0,}`` is the same as ``*``, ``{1,}``
|
||||
is equivalent to ``+``, and ``{0,1}`` is the same as ``?``. It's better to use
|
||||
``*``, ``+``, or ``?`` when you can, simply because they're shorter and easier
|
||||
|
@ -803,7 +803,7 @@ which matches the header's value.
|
|||
Groups are marked by the ``'('``, ``')'`` metacharacters. ``'('`` and ``')'``
|
||||
have much the same meaning as they do in mathematical expressions; they group
|
||||
together the expressions contained inside them, and you can repeat the contents
|
||||
of a group with a repeating qualifier, such as ``*``, ``+``, ``?``, or
|
||||
of a group with a quantifier, such as ``*``, ``+``, ``?``, or
|
||||
``{m,n}``. For example, ``(ab)*`` will match zero or more repetitions of
|
||||
``ab``. ::
|
||||
|
||||
|
@ -1326,7 +1326,7 @@ backtrack character by character until it finds a match for the ``>``. The
|
|||
final match extends from the ``'<'`` in ``'<html>'`` to the ``'>'`` in
|
||||
``'</title>'``, which isn't what you want.
|
||||
|
||||
In this case, the solution is to use the non-greedy qualifiers ``*?``, ``+?``,
|
||||
In this case, the solution is to use the non-greedy quantifiers ``*?``, ``+?``,
|
||||
``??``, or ``{m,n}?``, which match as *little* text as possible. In the above
|
||||
example, the ``'>'`` is tried immediately after the first ``'<'`` matches, and
|
||||
when it fails, the engine advances a character at a time, retrying the ``'>'``
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue