diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -105,8 +105,8 @@ ``'*'`` Causes the resulting RE to match 0 or more repetitions of the preceding RE, as - many repetitions as are possible. ``ab*`` will match 'a', 'ab', or 'a' followed - by any number of 'b's. + many repetitions as produce matches. ``ab*`` will match 'a', 'ab', or 'a' + followed by any number of 'b's. ``'+'`` Causes the resulting RE to match 1 or more repetitions of the preceding RE. @@ -133,10 +133,10 @@ ``{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. For example, - ``a{3,5}`` will match from 3 to 5 ``'a'`` characters. Omitting *m* specifies a - lower bound of zero, and omitting *n* specifies an infinite upper bound. As an - example, ``a{4,}b`` will match ``aaaab`` or a thousand ``'a'`` characters + RE, attempting to match as many repetitions as produce matches. For example, + ``a{3,5}`` will match from 3 to 5 ``'a'`` characters. Omitting *m* specifies + a lower bound of zero, and omitting *n* specifies an infinite upper bound. As + an example, ``a{4,}b`` will match ``aaaab`` or a thousand ``'a'`` characters followed by a ``b``, but not ``aaab``. The comma may not be omitted or the modifier would be confused with the previously described form. @@ -192,16 +192,17 @@ place it at the beginning of the set. For example, both ``[()[\]{}]`` and ``[]()[{}]`` will both match a parenthesis. -``'|'`` + ``'|'`` ``A|B``, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the ``'|'`` in this way. This can be used inside groups (see below) as well. As the target string is scanned, REs separated by ``'|'`` are tried from left to - right. When one pattern completely matches, that branch is accepted. This means - that once ``A`` matches, ``B`` will not be tested further, even if it would - produce a longer overall match. In other words, the ``'|'`` operator is never - greedy. To match a literal ``'|'``, use ``\|``, or enclose it inside a - character class, as in ``[|]``. + right. When one pattern completely matches, that branch is accepted. This + means that once ``A`` matches, ``B`` will not be tested further, even if it + would produce a longer overall match unless the main pattern would fail + (non-atomic, non-possessive behavior). In other words, the ``'|'`` operator + is never greedy. To match a literal ``'|'``, use ``\|``, or enclose it inside + a character class, as in ``[|]``. ``(...)`` Matches whatever regular expression is inside the parentheses, and indicates the