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

GH-98906re module:search() vs. match() section should mentionfullmatch()#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ericvsmith merged 9 commits intopython:mainfromramvikrams:t2
Nov 30, 2022

Conversation

@ramvikrams
Copy link
Contributor

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

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

adding re.fullmatch with it's examples

..sectionauthor::Fred L. Drake, Jr. <fdrake@acm.org>

Python offers two different primitive operations based on regular expressions:
Copy link
Contributor

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 theNone case can omitted since it wasn't mentioned in the previous two cases either.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done sir

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
Copy link
Contributor

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 andre.search can be swapped over, orre.fullmatch can be changed to single quote (but optional).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done the changes

Comment on lines 1567 to 1568
:func:`re.fullmatch` checks forentirestringto be a match.:func:`re.search`
checks for a match anywhere in the string (this is what Perldoes by default).
Copy link
Contributor

@slatenyslatenyNov 1, 2022
edited
Loading

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

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 plainre.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

Comment on lines 1567 to 1568
:func:`re.fullmatch` checks forentirestringto be a match.:func:`re.search`
checks for a match anywhere in the string (this is what Perldoes by default).
Copy link
Contributor

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 plainre.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

update the examples  where `re.match` and `re.search` shows a match but not `re.fullmatch`
<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
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")# Matchre.fullmatch("r.*n","python")# No match

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yes sir

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

done sir

>>> 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 thatsearch() can match something thatmatch() does not, with the same parameters to both.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yes sir

restrict the match at the beginning of the string::

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

I would not add this. This section is trying to show the differences betweensearch andmatch. Adding afullmatch example just confuses things.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yes sir

Copy link
Member

Choose a reason for hiding this comment

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

Please delete thefullmatch line here.

@bedevere-bot
Copy link

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 phraseI 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.

@ramvikrams
Copy link
ContributorAuthor

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

restrict the match at the beginning of the string::

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

Please delete thefullmatch line here.

>>> 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
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.

+: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
Copy link
Member

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 ofmatch, thensearch, thenfullmatch. That way the match the examples immediately below.

Copy link
Member

@ericvsmithericvsmith left a 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.

>>> 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?

@bedevere-bot
Copy link

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 phraseI 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.

@ericvsmithericvsmith self-assigned thisNov 30, 2022
@ramvikrams
Copy link
ContributorAuthor

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

@miss-islington
Copy link
Contributor

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

@bedevere-bot
Copy link

GH-99912 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelNov 30, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 30, 2022
…ould mention ```fullmatch()``` (pythonGH-98916)Mention fullmatch along with search and match.(cherry picked from commite0f91de)Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 30, 2022
…ould mention ```fullmatch()``` (pythonGH-98916)Mention fullmatch along with search and match.(cherry picked from commite0f91de)Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
@bedevere-bot
Copy link

GH-99913 is a backport of this pull request to the3.10 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.10only security fixes labelNov 30, 2022
@ramvikrams
Copy link
ContributorAuthor

thanks sir for your help

ericvsmith pushed a commit that referenced this pull requestNov 30, 2022
…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 commite0f91de)Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
ericvsmith pushed a commit that referenced this pull requestNov 30, 2022
…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 commite0f91de)Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
carljm added a commit to carljm/cpython that referenced this pull requestDec 1, 2022
* 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)  ...
@ramvikramsramvikrams deleted the t2 branchDecember 3, 2022 13:46
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hauntsaninjahauntsaninjahauntsaninja left review comments

@slatenyslatenyslateny left review comments

@ericvsmithericvsmithAwaiting requested review from ericvsmith

Assignees

@ericvsmithericvsmith

Labels

docsDocumentation in the Doc dirskip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@ramvikrams@bedevere-bot@miss-islington@ericvsmith@hauntsaninja@slateny

[8]ページ先頭

©2009-2025 Movatter.jp