@@ -1562,16 +1562,22 @@ search() vs. match()
15621562
15631563.. sectionauthor :: Fred L. Drake, Jr. <fdrake@acm.org>
15641564
1565- Python offers two different primitive operations based on regular expressions:
1566- :func: `re.match ` checks for a match only at the beginning of the string, while
1567- :func: `re.search ` checks for a match anywhere in the string (this is what Perl
1568- does by default).
1565+ Python offers different primitive operations based on regular expressions:
1566+
1567+ + :func: `re.match ` checks for a match only at the beginning of the string
1568+ + :func: `re.search ` checks for a match anywhere in the string
1569+ (this is what Perl does by default)
1570+ + :func: `re.fullmatch ` checks for entire string to be a match
1571+
15691572
15701573For example::
15711574
15721575 >>> re.match("c", "abcdef") # No match
15731576 >>> re.search("c", "abcdef") # Match
15741577 <re.Match object; span=(2, 3), match='c'>
1578+ >>> re.fullmatch("p.*n", "python") # Match
1579+ <re.Match object; span=(0, 6), match='python'>
1580+ >>> re.fullmatch("r.*n", "python") # No match
15751581
15761582Regular expressions beginning with ``'^' `` can be used with :func: `search ` to
15771583restrict the match at the beginning of the string::
@@ -1585,8 +1591,8 @@ Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
15851591beginning of the string, whereas using :func: `search ` with a regular expression
15861592beginning with ``'^' `` will match at the beginning of each line. ::
15871593
1588- >>> re.match('X', ' A\nB\nX' , re.MULTILINE) # No match
1589- >>> re.search('^X', ' A\nB\nX' , re.MULTILINE) # Match
1594+ >>> re.match("X", " A\nB\nX" , re.MULTILINE) # No match
1595+ >>> re.search("^X", " A\nB\nX" , re.MULTILINE) # Match
15901596 <re.Match object; span=(4, 5), match='X'>
15911597
15921598
0 commit comments