Skip to content

Commit e0f91de

Browse files
authored
GH-98906 re module: search() vs. match() section should mention fullmatch() (GH-98916)
Mention fullmatch along with search and match.
1 parent 7877642 commit e0f91de

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
@@ -1565,16 +1565,22 @@ search() vs. match()
15651565

15661566
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
15671567

1568-
Python offers two different primitive operations based on regular expressions:
1569-
:func:`re.match` checks for a match only at the beginning of the string, while
1570-
:func:`re.search` checks for a match anywhere in the string (this is what Perl
1571-
does by default).
1568+
Python offers different primitive operations based on regular expressions:
1569+
1570+
+ :func:`re.match` checks for a match only at the beginning of the string
1571+
+ :func:`re.search` checks for a match anywhere in the string
1572+
(this is what Perl does by default)
1573+
+ :func:`re.fullmatch` checks for entire string to be a match
1574+
15721575

15731576
For example::
15741577

15751578
>>> re.match("c", "abcdef") # No match
15761579
>>> re.search("c", "abcdef") # Match
15771580
<re.Match object; span=(2, 3), match='c'>
1581+
>>> re.fullmatch("p.*n", "python") # Match
1582+
<re.Match object; span=(0, 6), match='python'>
1583+
>>> re.fullmatch("r.*n", "python") # No match
15781584

15791585
Regular expressions beginning with ``'^'`` can be used with :func:`search` to
15801586
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
15881594
beginning of the string, whereas using :func:`search` with a regular expression
15891595
beginning with ``'^'`` will match at the beginning of each line. ::
15901596

1591-
>>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
1592-
>>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
1597+
>>> re.match("X", "A\nB\nX", re.MULTILINE) # No match
1598+
>>> re.search("^X", "A\nB\nX", re.MULTILINE) # Match
15931599
<re.Match object; span=(4, 5), match='X'>
15941600

15951601

0 commit comments

Comments
 (0)