Skip to content

Commit 80f4624

Browse files
[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 e0f91de) Co-authored-by: ram vikram singh <ramvikrams243@gmail.com> Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
1 parent 3baaa97 commit 80f4624

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Doc/library/re.rst

+12-6
Original file line numberDiff line numberDiff line change
@@ -1471,16 +1471,22 @@ search() vs. match()
14711471

14721472
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
14731473

1474-
Python offers two different primitive operations based on regular expressions:
1475-
:func:`re.match` checks for a match only at the beginning of the string, while
1476-
:func:`re.search` checks for a match anywhere in the string (this is what Perl
1477-
does by default).
1474+
Python offers different primitive operations based on regular expressions:
1475+
1476+
+ :func:`re.match` checks for a match only at the beginning of the string
1477+
+ :func:`re.search` checks for a match anywhere in the string
1478+
(this is what Perl does by default)
1479+
+ :func:`re.fullmatch` checks for entire string to be a match
1480+
14781481

14791482
For example::
14801483

14811484
>>> re.match("c", "abcdef") # No match
14821485
>>> re.search("c", "abcdef") # Match
14831486
<re.Match object; span=(2, 3), match='c'>
1487+
>>> re.fullmatch("p.*n", "python") # Match
1488+
<re.Match object; span=(0, 6), match='python'>
1489+
>>> re.fullmatch("r.*n", "python") # No match
14841490

14851491
Regular expressions beginning with ``'^'`` can be used with :func:`search` to
14861492
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
14941500
beginning of the string, whereas using :func:`search` with a regular expression
14951501
beginning with ``'^'`` will match at the beginning of each line. ::
14961502

1497-
>>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
1498-
>>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
1503+
>>> re.match("X", "A\nB\nX", re.MULTILINE) # No match
1504+
>>> re.search("^X", "A\nB\nX", re.MULTILINE) # Match
14991505
<re.Match object; span=(4, 5), match='X'>
15001506

15011507

0 commit comments

Comments
 (0)