Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4511d3

Browse files
[3.11]GH-98906re module:search() vs. match() section should mentionfullmatch() (GH-98916) (GH-99912)
GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (GH-98916)Mention fullmatch along with search and match.(cherry picked from commite0f91de)Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
1 parent90701eb commitf4511d3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

‎Doc/library/re.rst‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

15701573
For 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

15761582
Regular expressions beginning with ``'^'`` can be used with:func:`search` to
15771583
restrict 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
15851591
beginning of the string, whereas using:func:`search` with a regular expression
15861592
beginning 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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp