-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
bpo-47081: Replace "qualifiers" with "quantifiers" in the re module documentation #32028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ Some characters, like ``'|'`` or ``'('``, are special. Special | |
| characters either stand for classes of ordinary characters, or affect | ||
| how the regular expressions around them are interpreted. | ||
|
|
||
| Repetition qualifiers (``*``, ``+``, ``?``, ``{m,n}``, etc) cannot be | ||
| Repetition operators or quantifiers (``*``, ``+``, ``?``, ``{m,n}``, etc) cannot be | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap at 80 chars.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not PEP 8, but some other PEP for documentation. In any case a common sense is the main principle. |
||
| directly nested. This avoids ambiguity with the non-greedy modifier suffix | ||
| ``?``, and with other modifiers in other implementations. To apply a second | ||
| repetition to an inner repetition, parentheses may be used. For example, | ||
|
|
@@ -146,10 +146,10 @@ The special characters are: | |
| single: ??; in regular expressions | ||
|
|
||
| ``*?``, ``+?``, ``??`` | ||
| The ``'*'``, ``'+'``, and ``'?'`` qualifiers are all :dfn:`greedy`; they match | ||
| The ``'*'``, ``'+'``, and ``'?'`` quantifiers are all :dfn:`greedy`; they match | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap at 80 chars. |
||
| as much text as possible. Sometimes this behaviour isn't desired; if the RE | ||
| ``<.*>`` is matched against ``'<a> b <c>'``, it will match the entire | ||
| string, and not just ``'<a>'``. Adding ``?`` after the qualifier makes it | ||
| string, and not just ``'<a>'``. Adding ``?`` after the quantifier makes it | ||
| perform the match in :dfn:`non-greedy` or :dfn:`minimal` fashion; as *few* | ||
| characters as possible will be matched. Using the RE ``<.*?>`` will match | ||
| only ``'<a>'``. | ||
|
|
@@ -160,11 +160,11 @@ The special characters are: | |
| single: ?+; in regular expressions | ||
|
|
||
| ``*+``, ``++``, ``?+`` | ||
| Like the ``'*'``, ``'+'``, and ``'?'`` qualifiers, those where ``'+'`` is | ||
| Like the ``'*'``, ``'+'``, and ``'?'`` quantifiers, those where ``'+'`` is | ||
| appended also match as many times as possible. | ||
| However, unlike the true greedy qualifiers, these do not allow | ||
| However, unlike the true greedy quantifiers, these do not allow | ||
| back-tracking when the expression following it fails to match. | ||
| These are known as :dfn:`possessive` qualifiers. | ||
| These are known as :dfn:`possessive` quantifiers. | ||
| For example, ``a*a`` will match ``'aaaa'`` because the ``a*`` will match | ||
| all 4 ``'a'``s, but, when the final ``'a'`` is encountered, the | ||
| expression is backtracked so that in the end the ``a*`` ends up matching | ||
|
|
@@ -198,15 +198,15 @@ The special characters are: | |
| ``{m,n}?`` | ||
| Causes the resulting RE to match from *m* to *n* repetitions of the preceding | ||
| RE, attempting to match as *few* repetitions as possible. This is the | ||
| non-greedy version of the previous qualifier. For example, on the | ||
| non-greedy version of the previous quantifier. For example, on the | ||
| 6-character string ``'aaaaaa'``, ``a{3,5}`` will match 5 ``'a'`` characters, | ||
| while ``a{3,5}?`` will only match 3 characters. | ||
|
|
||
| ``{m,n}+`` | ||
| Causes the resulting RE to match from *m* to *n* repetitions of the | ||
| preceding RE, attempting to match as many repetitions as possible | ||
| *without* establishing any backtracking points. | ||
| This is the possessive version of the qualifier above. | ||
| This is the possessive version of the quantifier above. | ||
| For example, on the 6-character string ``'aaaaaa'``, ``a{3,5}+aa`` | ||
| attempt to match 5 ``'a'`` characters, then, requiring 2 more ``'a'``s, | ||
| will need more characters than available and thus fail, while | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| Add support of atomic grouping (``(?>...)``) and possessive qualifiers | ||
| Add support of atomic grouping (``(?>...)``) and possessive quantifiers | ||
| (``*+``, ``++``, ``?+``, ``{m,n}+``) in :mod:`regular expressions <re>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap at 80 chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that in this case it is better to keep a line slightly longer that 80 characters than split it on two very short lines or reformat the whole paragraph. PEP 8 allows some liberty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrongly assumed that in Python docs (as we do in Django docs) re-wrapping is stricter. TIL. Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small compromises are possible. If it would be a new text, it would be stricter.