@@ -1471,16 +1471,22 @@ search() vs. match()
14711471
14721472..
sectionauthor ::
Fred L. Drake, Jr. <[email protected] > 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
14791482For 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
14851491Regular expressions beginning with ``'^' `` can be used with :func: `search ` to
14861492restrict 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
14941500beginning of the string, whereas using :func: `search ` with a regular expression
14951501beginning 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