8000 GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` by ramvikrams · Pull Request #98916 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-98906 re module: search() vs. match() section should mention fullmatch() #98916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated the docs
  • Loading branch information
ramvikrams authored Nov 30, 2022
commit a650b40b19f4614358beab567d0ec9a39c844737
17 changes: 9 additions & 8 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1575,11 +1575,12 @@ Python offers different primitive operations based on regular expressions:

For example::

>>> re.match("c", "cdef") # match
<re.Match object; span=(0, 1), match='c'>
>>> re.search("c", "cdef") # Match
<re.Match object; span=(0, 1), match='c'>
>>> re.fullmatch("c", "cdef") # No Match
>>> re.match("c", "abcdef") # No match
>>> re.search("c", "abcdef") # Match
<re.Match object; span=(2, 3), match='c'>
>>> re.fullmatch("p.*n", "python")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this: Can you add the "# Match" comment to this line?

<re.Match object; span=(0, 6), match='python'>
>>> re.fullmatch("r.*n", "python") # No match

Regular expressions beginning with ``'^'`` can be used with :func:`search` to
restrict the match at the beginning of the string::
Expand All @@ -1594,9 +1595,9 @@ Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
beginning of the string, whereas using :func:`search` with a regular expression
beginning with ``'^'`` will match at the beginning of each line. ::

>>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
>>> re.fullmatch('X', "A\nB\nX", re.MULTILINE) # No Match
>>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
>>> re.match("X", "A\nB\nX", re.MULTILINE) # No match
>>> re.fullmatch("X", "A\nB\nX", re.MULTILINE) # No Match
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And delete thisfullmatch line also. This section doesn't need to mention fullmatch.

>>> re.search("^X", "A\nB\nX", re.MULTILINE) # Match
<re.Match object; span=(4, 5), match='X'>


Expand Down
0