From: ram vikram singh Date: Wed, 30 Nov 2022 22:52:21 +0000 (+0530) Subject: GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullma... X-Git-Tag: v3.12.0a3~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0f91deb5930ecb02e7f8ced9bd82609e6889fb0;p=thirdparty%2FPython%2Fcpython.git GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (GH-98916) Mention fullmatch along with search and match. --- diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 0034b46fb1ce..e6e242320fd8 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1565,16 +1565,22 @@ search() vs. match() .. sectionauthor:: Fred L. Drake, Jr. -Python offers two different primitive operations based on regular expressions: -:func:`re.match` checks for a match only at the beginning of the string, while -:func:`re.search` checks for a match anywhere in the string (this is what Perl -does by default). +Python offers different primitive operations based on regular expressions: + ++ :func:`re.match` checks for a match only at the beginning of the string ++ :func:`re.search` checks for a match anywhere in the string + (this is what Perl does by default) ++ :func:`re.fullmatch` checks for entire string to be a match + For example:: >>> re.match("c", "abcdef") # No match >>> re.search("c", "abcdef") # Match + >>> re.fullmatch("p.*n", "python") # Match + + >>> re.fullmatch("r.*n", "python") # No match Regular expressions beginning with ``'^'`` can be used with :func:`search` to restrict the match at the beginning of the string:: @@ -1588,8 +1594,8 @@ Note however that in :const:`MULTILINE` mode :func:`match` only matches at the beginning of the string, whereas using :func:`search` with a regular expression beginning with ``'^'`` will match at the beginning of each line. :: - >>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match - >>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match + >>> re.match("X", "A\nB\nX", re.MULTILINE) # No match + >>> re.search("^X", "A\nB\nX", re.MULTILINE) # Match