Skip to content
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'>
Comment thread
ericvsmith marked this conversation as resolved.
>>> 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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