summaryrefslogtreecommitdiffstats
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-11-23 21:20:30 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-11-23 21:20:30 (GMT)
commit32eddc1bbc47479a3639b9191ffc82a52903c5f4 (patch)
tree8ce67ed6f7d6db96277f4e6d07457f2b159fb362 /Doc/library/re.rst
parent3ed82c55a85665a33b821064c1911b4aa09301d9 (diff)
downloadcpython-32eddc1bbc47479a3639b9191ffc82a52903c5f4.zip
cpython-32eddc1bbc47479a3639b9191ffc82a52903c5f4.tar.gz
cpython-32eddc1bbc47479a3639b9191ffc82a52903c5f4.tar.bz2
Issue #16203: Add re.fullmatch() function and regex.fullmatch() method,
which anchor the pattern at both ends of the string to match. Original patch by Matthew Barnett.
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst30
1 files changed, 29 insertions, 1 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 220ce86..fa6a9ce 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -481,7 +481,7 @@ form.
.. note::
The compiled versions of the most recent patterns passed to
- :func:`re.match`, :func:`re.search` or :func:`re.compile` are cached, so
+ :func:`re.compile` and the module-level matching functions are cached, so
programs that use only a few regular expressions at a time needn't worry
about compiling regular expressions.
@@ -584,6 +584,16 @@ form.
instead (see also :ref:`search-vs-match`).
+.. function:: fullmatch(pattern, string, flags=0)
+
+ If the whole *string* matches the regular expression *pattern*, return a
+ corresponding :ref:`match object <match-objects>`. Return ``None`` if the
+ string does not match the pattern; note that this is different from a
+ zero-length match.
+
+ .. versionadded:: 3.4
+
+
.. function:: split(pattern, string, maxsplit=0, flags=0)
Split *string* by the occurrences of *pattern*. If capturing parentheses are
@@ -778,6 +788,24 @@ attributes:
:meth:`~regex.search` instead (see also :ref:`search-vs-match`).
+.. method:: regex.fullmatch(string[, pos[, endpos]])
+
+ If the whole *string* matches this regular expression, return a corresponding
+ :ref:`match object <match-objects>`. Return ``None`` if the string does not
+ match the pattern; note that this is different from a zero-length match.
+
+ The optional *pos* and *endpos* parameters have the same meaning as for the
+ :meth:`~regex.search` method.
+
+ >>> pattern = re.compile("o[gh]")
+ >>> pattern.fullmatch("dog") # No match as "o" is not at the start of "dog".
+ >>> pattern.fullmatch("ogre") # No match as not the full string matches.
+ >>> pattern.fullmatch("doggie", 1, 3) # Matches within given limits.
+ <_sre.SRE_Match object at ...>
+
+ .. versionadded:: 3.4
+
+
.. method:: regex.split(string, maxsplit=0)
Identical to the :func:`split` function, using the compiled pattern.