#1208: document match object's boolean value.
This commit is contained in:
parent
90d93615d6
commit
ba2e519082
|
@ -28,14 +28,14 @@ The solution is to use Python's raw string notation for regular expression
|
||||||
patterns; backslashes are not handled in any special way in a string literal
|
patterns; backslashes are not handled in any special way in a string literal
|
||||||
prefixed with ``'r'``. So ``r"\n"`` is a two-character string containing
|
prefixed with ``'r'``. So ``r"\n"`` is a two-character string containing
|
||||||
``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a
|
``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a
|
||||||
newline. Usually patterns will be expressed in Python code using this raw string
|
newline. Usually patterns will be expressed in Python code using this raw
|
||||||
notation.
|
string notation.
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
Mastering Regular Expressions
|
Mastering Regular Expressions
|
||||||
Book on regular expressions by Jeffrey Friedl, published by O'Reilly. The
|
Book on regular expressions by Jeffrey Friedl, published by O'Reilly. The
|
||||||
second edition of the book no longer covers Python at all, but the first
|
second edition of the book no longer covers Python at all, but the first
|
||||||
edition covered writing good regular expression patterns in great detail.
|
edition covered writing good regular expression patterns in great detail.
|
||||||
|
|
||||||
|
|
||||||
|
@ -428,8 +428,8 @@ form.
|
||||||
|
|
||||||
.. function:: compile(pattern[, flags])
|
.. function:: compile(pattern[, flags])
|
||||||
|
|
||||||
Compile a regular expression pattern into a regular expression object, which can
|
Compile a regular expression pattern into a regular expression object, which
|
||||||
be used for matching using its :func:`match` and :func:`search` methods,
|
can be used for matching using its :func:`match` and :func:`search` methods,
|
||||||
described below.
|
described below.
|
||||||
|
|
||||||
The expression's behaviour can be modified by specifying a *flags* value.
|
The expression's behaviour can be modified by specifying a *flags* value.
|
||||||
|
@ -445,8 +445,8 @@ form.
|
||||||
|
|
||||||
result = re.match(pat, str)
|
result = re.match(pat, str)
|
||||||
|
|
||||||
but the version using :func:`compile` is more efficient when the expression will
|
but the version using :func:`compile` is more efficient when the expression
|
||||||
be used several times in a single program.
|
will be used several times in a single program.
|
||||||
|
|
||||||
.. % (The compiled version of the last pattern passed to
|
.. % (The compiled version of the last pattern passed to
|
||||||
.. % \function{re.match()} or \function{re.search()} is cached, so
|
.. % \function{re.match()} or \function{re.search()} is cached, so
|
||||||
|
@ -464,8 +464,8 @@ form.
|
||||||
.. data:: L
|
.. data:: L
|
||||||
LOCALE
|
LOCALE
|
||||||
|
|
||||||
Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the current
|
Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the
|
||||||
locale.
|
current locale.
|
||||||
|
|
||||||
|
|
||||||
.. data:: M
|
.. data:: M
|
||||||
|
@ -554,10 +554,11 @@ form.
|
||||||
|
|
||||||
.. function:: findall(pattern, string[, flags])
|
.. function:: findall(pattern, string[, flags])
|
||||||
|
|
||||||
Return a list of all non-overlapping matches of *pattern* in *string*. If one
|
Return all non-overlapping matches of *pattern* in *string*, as a list of
|
||||||
or more groups are present in the pattern, return a list of groups; this will be
|
strings. If one or more groups are present in the pattern, return a list of
|
||||||
a list of tuples if the pattern has more than one group. Empty matches are
|
groups; this will be a list of tuples if the pattern has more than one group.
|
||||||
included in the result unless they touch the beginning of another match.
|
Empty matches are included in the result unless they touch the beginning of
|
||||||
|
another match.
|
||||||
|
|
||||||
.. versionadded:: 1.5.2
|
.. versionadded:: 1.5.2
|
||||||
|
|
||||||
|
@ -567,9 +568,9 @@ form.
|
||||||
|
|
||||||
.. function:: finditer(pattern, string[, flags])
|
.. function:: finditer(pattern, string[, flags])
|
||||||
|
|
||||||
Return an iterator over all non-overlapping matches for the RE *pattern* in
|
Return an iterator yielding :class:`MatchObject` instances over all
|
||||||
*string*. For each match, the iterator returns a match object. Empty matches
|
non-overlapping matches for the RE *pattern* in *string*. Empty matches are
|
||||||
are included in the result unless they touch the beginning of another match.
|
included in the result unless they touch the beginning of another match.
|
||||||
|
|
||||||
.. versionadded:: 2.2
|
.. versionadded:: 2.2
|
||||||
|
|
||||||
|
@ -737,7 +738,9 @@ attributes:
|
||||||
Match Objects
|
Match Objects
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
:class:`MatchObject` instances support the following methods and attributes:
|
Match objects always have a boolean value of :const:`True`, so that you can test
|
||||||
|
whether e.g. :func:`match` resulted in a match with a simple if statement. They
|
||||||
|
support the following methods and attributes:
|
||||||
|
|
||||||
|
|
||||||
.. method:: MatchObject.expand(template)
|
.. method:: MatchObject.expand(template)
|
||||||
|
|
Loading…
Reference in New Issue