diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-30 23:14:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-30 23:14:47 (GMT) |
commit | 80f4624f8e5a56dbf3882a8c3722fb5a17c390b9 (patch) | |
tree | 5d3c0bba685ee7c8de0611a2f249e2ec4d8da644 | |
parent | 3baaa97d6c0bec6959d44ceaf0cdfc49577ada82 (diff) | |
download | cpython-80f4624f8e5a56dbf3882a8c3722fb5a17c390b9.zip cpython-80f4624f8e5a56dbf3882a8c3722fb5a17c390b9.tar.gz cpython-80f4624f8e5a56dbf3882a8c3722fb5a17c390b9.tar.bz2 |
[3.10] GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (GH-98916) (GH-99913)
GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (GH-98916)
Mention fullmatch along with search and match.
(cherry picked from commit e0f91deb5930ecb02e7f8ced9bd82609e6889fb0)
Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
-rw-r--r-- | Doc/library/re.rst | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 40e2dcc..a40c99b 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1471,16 +1471,22 @@ search() vs. match() .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> -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.Match object; span=(2, 3), match='c'> + >>> re.fullmatch("p.*n", "python") # Match + <re.Match object; span=(0, 6), match='python'> + >>> 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:: @@ -1494,8 +1500,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 <re.Match object; span=(4, 5), match='X'> |