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
update the examples
update the examples  where `re.match` and `re.search` shows a match but not `re.fullmatch`
  • Loading branch information
ramvikrams authored Nov 30, 2022
commit 84fc8c8fb7f90a9847f23b57a86117dd3a105158
10 changes: 5 additions & 5 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1575,11 +1575,11 @@ Python offers different primitive operations based on regular expressions:

For example::

>>> re.match("c", "abcdef") # No match
>>> re.search("c", "abcdef") # Match
<re.Match object; span=(2, 3), match='c'>
>>> re.fullmatch("python", "python") # Match
<re.Match object; span=(0, 6), match='python'>
>>> 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'>
Copy link
Member

Choose a reason for hiding this comment

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

And I would not add these 2 examples. The existing examples are fine. The goal is to show that search() can match something that match() does not, with the same parameters to both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes sir

>>> re.fullmatch("c", "cdef") # 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.

Sorry I wasn't clear. I think you need two examples for fullmatch:

re.fullmatch("p.*n", "python")  # Match
re.fullmatch("r.*n", "python") # No match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes sir

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done sir


Regular expressions beginning with ``'^'`` can be used with :func:`search` to
restrict the match at the beginning of the string::
Expand Down
0