GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` by ramvikrams · Pull Request #98916 · python/cpython

Conversation

@ramvikrams

@ramvikrams ramvikrams commented Oct 31, 2022

Copy link
Copy Markdown
Contributor

Added the re.fullmatch() with it's examples

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ramvikrams
for python#98906
7e90e14
adding re.fullmatch with it's examples
@bedevere-bot bedevere-bot mentioned this pull request Oct 31, 2022
re module: search() vs. match() section should mention fullmatch() #98906
Closed
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir skip news awaiting review labels Oct 31, 2022
slateny
slateny reviewed Nov 1, 2022
View reviewed changes
Comment thread Doc/library/re.rst Outdated
@@ -1565,18 +1565,22 @@ search() vs. match()
Python offers two different primitive operations based on regular expressions:

@slateny slateny Nov 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe continue the style of this paragraph, so instead something like 'Python offers a few primitive ...' then '... re.fullmatch checks that the whole string is a match ...' (can change this wording up a bit too). I also think the None case can omitted since it wasn't mentioned in the previous two cases either.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done sir

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
@@ -1586,6 +1590,7 @@ 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

@slateny slateny Nov 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For consistency, other examples seem to use double quotes so this and re.search can be swapped over, or re.fullmatch can be changed to single quote (but optional).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done the changes

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ramvikrams added 2 commits November 1, 2022 09:53
@ramvikrams
changes
9a1bc61
@ramvikrams
update
afab961
slateny
slateny reviewed Nov 1, 2022
View reviewed changes
Comment thread Doc/library/re.rst Outdated
Comment on lines +1567 to +1568
:func:`re.fullmatch` checks for entire string to be a match. :func:`re.search`
checks for a match anywhere in the string (this is what Perl does by default).

@slateny slateny Nov 1, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For better flow

Suggested change
:func:`re.fullmatch` checks for entire string to be a match. :func:`re.search`
checks for a match anywhere in the string (this is what Perl does by default).
:func:`re.fullmatch` checks for entire string to be a match, and
:func:`re.search` checks for a match anywhere in the string
(this is what Perl does by default).

or perhaps even

Suggested change
:func:`re.fullmatch` checks for entire string to be a match. :func:`re.search`
checks for a match anywhere in the string (this is what Perl does by default).
:func:`re.fullmatch` checks for entire string to be a match, and
:func:`re.search` checks for a match anywhere in the string.

but I'll let Eric decide whether the Perl mention is necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ok

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hauntsaninja hauntsaninja Nov 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

My recommendation would be to use bullet points (and to reorder so that plain re.match is last, honestly it's a little bit of a footgun)

* :func:`re.search` checks for a match anywhere in the string
  (this is what Perl does by default)
* :func:`re.fullmatch` checks for entire string to be a match
* :func:`re.match` checks for a match only at the beginning of the string

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slateny
slateny requested a review from ericvsmith November 1, 2022 06:23
hauntsaninja
hauntsaninja reviewed Nov 1, 2022
View reviewed changes
Comment thread Doc/library/re.rst Outdated
Comment on lines +1567 to +1568
:func:`re.fullmatch` checks for entire string to be a match. :func:`re.search`
checks for a match anywhere in the string (this is what Perl does by default).

@hauntsaninja hauntsaninja Nov 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

My recommendation would be to use bullet points (and to reorder so that plain re.match is last, honestly it's a little bit of a footgun)

* :func:`re.search` checks for a match anywhere in the string
  (this is what Perl does by default)
* :func:`re.fullmatch` checks for entire string to be a match
* :func:`re.match` checks for a match only at the beginning of the string

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ramvikrams
update
f827986
@ramvikrams ramvikrams closed this Nov 30, 2022
@ramvikrams
ramvikrams deleted the t2 branch November 30, 2022 19:59
@ramvikrams
ramvikrams restored the t2 branch November 30, 2022 19:59
@ramvikrams
Merge branch 'python:main' into t2
95efa61
@ramvikrams ramvikrams reopened this Nov 30, 2022
@ramvikrams
update the examples
84fc8c8
update the examples  where `re.match` and `re.search` shows a match but not `re.fullmatch`
ericvsmith
ericvsmith requested changes Nov 30, 2022
View reviewed changes
Comment thread Doc/library/re.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/re.rst Outdated
<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

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

yes sir

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

done sir

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
>>> 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'>

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

yes sir

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
restrict the match at the beginning of the string::

>>> re.match("c", "abcdef") # No match
>>> re.fullmatch("c", "abcdef") # No Match

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would not add this. This section is trying to show the differences between search and match. Adding a fullmatch example just confuses things.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ramvikrams ramvikrams Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

yes sir

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please delete the fullmatch line here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting review labels Nov 30, 2022
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ramvikrams
updated the docs
a650b40
@ramvikrams

ramvikrams commented Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Nov 30, 2022
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

Thanks for making the requested changes!

@ericvsmith: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot
bedevere-bot requested a review from ericvsmith November 30, 2022 21:57
ericvsmith
ericvsmith requested changes Nov 30, 2022
View reviewed changes
Comment thread Doc/library/re.rst Outdated
restrict the match at the beginning of the string::

>>> re.match("c", "abcdef") # No match
>>> re.fullmatch("c", "abcdef") # No Match

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please delete the fullmatch line here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
>>> re.match('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

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
+ :func:`re.search` checks for a match anywhere in the string,
(this is what Perl does by default)
+ :func:`re.fullmatch` checks for entire string to be a match
+ :func:`re.match` checks for a match only at the beginning of the string

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please leave these in the order of match, then search, then fullmatch. That way the match the examples immediately below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot removed the awaiting change review label Nov 30, 2022
@bedevere-bot
bedevere-bot requested a review from ericvsmith November 30, 2022 22:30
ericvsmith
ericvsmith requested changes Nov 30, 2022
View reviewed changes

@ericvsmith ericvsmith left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sorry for one additional small change. I'll commit it after this change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/re.rst Outdated
>>> re.match("c", "abcdef") # No match
>>> re.search("c", "abcdef") # Match
<re.Match object; span=(2, 3), match='c'>
>>> re.fullmatch("p.*n", "python")

@ericvsmith ericvsmith Nov 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting change review labels Nov 30, 2022
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ramvikrams
Update re.rst
d2a6981
@ericvsmith ericvsmith self-assigned this Nov 30, 2022
@ramvikrams

ramvikrams commented Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Nov 30, 2022
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

Thanks for making the requested changes!

@ericvsmith: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericvsmith ericvsmith added awaiting changes needs backport to 3.10 needs backport to 3.11 only security fixes and removed awaiting change review labels Nov 30, 2022
@bedevere-bot
bedevere-bot requested a review from ericvsmith November 30, 2022 22:47
@ericvsmith
ericvsmith merged commit e0f91de into python:main Nov 30, 2022
@miss-islington

miss-islington commented Nov 30, 2022

Copy link
Copy Markdown
Contributor

Thanks @ramvikrams for the PR, and @ericvsmith for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting changes label Nov 30, 2022
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

GH-99912 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 30, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 30, 2022
@ramvikrams @miss-islington
pythonGH-98906 re module: search() vs. match() section sh…
f03bee1
…ould mention ```fullmatch()``` (pythonGH-98916)

Mention fullmatch along with search and match.
(cherry picked from commit e0f91de)

Co-authored-by: ram vikram singh <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 30, 2022
@ramvikrams @miss-islington
pythonGH-98906 re module: search() vs. match() section sh…
5d48832
…ould mention ```fullmatch()``` (pythonGH-98916)

Mention fullmatch along with search and match.
(cherry picked from commit e0f91de)

Co-authored-by: ram vikram singh <[email protected]>
@bedevere-bot

bedevere-bot commented Nov 30, 2022

Copy link
Copy Markdown

GH-99913 is a backport of this pull request to the 3.10 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 label Nov 30, 2022
@ramvikrams

ramvikrams commented Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

thanks sir for your help

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ericvsmith pushed a commit that referenced this pull request Nov 30, 2022
@miss-islington @ramvikrams
[3.11] GH-98906 re module: search() vs. match() section s…
f4511d3
…hould mention ```fullmatch()``` (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 commit e0f91de)

Co-authored-by: ram vikram singh <[email protected]>

Co-authored-by: ram vikram singh <[email protected]>
ericvsmith pushed a commit that referenced this pull request Nov 30, 2022
@miss-islington @ramvikrams
[3.10] GH-98906 re module: search() vs. match() section s…
80f4624
…hould mention ```fullmatch()``` (GH-98916) (GH-99913)

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

Mention fullmatch along with search and match.
(cherry picked from commit e0f91de)

Co-authored-by: ram vikram singh <[email protected]>

Co-authored-by: ram vikram singh <[email protected]>
carljm added a commit to carljm/cpython that referenced this pull request Dec 1, 2022
@carljm
Merge branch 'main' into fixinspect
12f7659
* main: (112 commits)
  pythongh-99894: Ensure the local names don't collide with the test file in traceback suggestion error checking (python#99895)
  pythongh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (pythonGH-99613)
  Doc: Add summary line to isolation_level & autocommit sqlite3.connect params (python#99917)
  pythonGH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (pythonGH-98916)
  pythongh-89189: More compact range iterator (pythonGH-27986)
  bpo-47220: Document the optional callback parameter of weakref.WeakMethod (pythonGH-25491)
  pythonGH-99905: Fix output of misses in summarize_stats.py execution counts (pythonGH-99906)
  pythongh-99845: PEP 670: Convert PyObject macros to functions (python#99850)
  pythongh-99845: Use size_t type in __sizeof__() methods (python#99846)
  pythonGH-99877)
  Fix typo in exception message in `multiprocessing.pool` (python#99900)
  pythongh-87092: move all localsplus preparation into separate function called from assembler stage (pythonGH-99869)
  pythongh-99891: Fix infinite recursion in the tokenizer when showing warnings (pythonGH-99893)
  pythongh-99824: Document that sqlite3.connect implicitly open a transaction if autocommit=False (python#99825)
  pythonGH-81057: remove static state from suggestions.c (python#99411)
  Improve zip64 limit error message (python#95892)
  pythongh-98253: Break potential reference cycles in external code worsened by typing.py lru_cache (python#98591)
  pythongh-99127: Allow some features of syslog to the main interpreter only (pythongh-99128)
  pythongh-82836: fix private network check (python#97733)
  Docs: improve accuracy of socketserver reference (python#24767)
  ...
@ramvikrams
ramvikrams deleted the t2 branch December 3, 2022 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja left review comments
@slateny slateny slateny left review comments
@ericvsmith ericvsmith Awaiting requested review from ericvsmith

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ericvsmith ericvsmith

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ramvikrams @bedevere-bot @miss-islington @ericvsmith @hauntsaninja @slateny
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.