diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-11-04 04:46:28 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-11-04 04:46:28 (GMT) |
commit | 51c374dede0e81ec508c552d21faf019da0b6b20 (patch) | |
tree | cc3c8f765c55603d7415d0336d9f68bab6035c1e /Doc | |
parent | 93d628b3780900f42e1d4c36cbeb0f5db3781198 (diff) | |
download | cpython-51c374dede0e81ec508c552d21faf019da0b6b20.zip cpython-51c374dede0e81ec508c552d21faf019da0b6b20.tar.gz cpython-51c374dede0e81ec508c552d21faf019da0b6b20.tar.bz2 |
#16304: clarify match objects docs. Initial patch by Jan Duzinkiewicz.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/re.rst | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index e6e20d6..1af4cf2 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -797,9 +797,16 @@ Match Objects .. class:: MatchObject - 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: + Match objects always have a boolean value of ``True``. + Since :meth:`~regex.match` and :meth:`~regex.search` return ``None`` + when there is no match, you can test whether there was a match with a simple + ``if`` statement:: + + match = re.search(pattern, string) + if match: + process(match) + + Match objects support the following methods and attributes: .. method:: MatchObject.expand(template) |