-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
re: Add support for start- and endpos. #14179
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
base: master
Are you sure you want to change the base?
re: Add support for start- and endpos. #14179
Conversation
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14179 +/- ##
=======================================
Coverage 98.44% 98.44%
=======================================
Files 171 171
Lines 22208 22220 +12
=======================================
+ Hits 21863 21875 +12
Misses 345 345 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Just to be clear: 'match' doesn't mean it's CPython-compatible (and hence the use of a .exp file for the tests)? In that case this feature feels somewhat confusing and hard to discover, and will likely remain underused? |
Oh- it was my intention that it would be CPython compatible. I took the tests from their documentation.
I didn’t realize that EXP files were optional for tests. I’ll take it out.
Thanks.
…On Tue, Mar 26, 2024 at 02:03 stinos ***@***.***> wrote:
This adds support to match the CPython re module which supports searching
and matching a substring using a start- and end-pos specified in the
corresponding Pattern method
Just to be clear: 'match' doesn't mean it's CPython-compatible (and hence
the use of a .exp file for the tests)?
—
Reply to this email directly, view it on GitHub
<#14179 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFECSTVCAFGVJI4NHYNX73Y2EFSXAVCNFSM6AAAAABFICO2QSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJZGUZDQOBWGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I was a bit excited and went ahead and added a |
b191a01
to
8c28d63
Compare
} | ||
else if (endpos < startpos) { | ||
endpos = startpos; | ||
} |
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 add a test case that tests this line.
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.
Thanks, @dpgeorge, I did.
5ad16c3
to
cf778ac
Compare
Sorry, this PR got a bit lost...
OK, so that increases the scope somewhat of this PR 😅 It would be good to know what the code size impact is for just the start/endpos change. To that end, probably best to keep this PR just for start/endpos (including tests for that), and have a separate PR for finditer. That makes it easier to review. |
e602699
to
dbe3f83
Compare
Pattern objects have two additional parameters for the ::search and ::match methods to define the starting and ending position of the subject within the string to be searched. This allows for searching a sub-string without creating a slice. However, one caveat of using the start-pos rather than a slice is that the start anchor (`^`) remains anchored to the beginning of the text. Signed-off-by: Jared Hancock <jared@greezybacon.me>
dbe3f83
to
d2813a1
Compare
Thanks, @dpgeorge. I really appreciate the review and feedback. I have separated the |
This adds support to match the CPython
re
module which supportssearch
ing andmatch
ing a substring using a start- and end-pos specified in the corresponding Pattern method.Pattern objects have two additional parameters for the ::search and ::match methods to define the starting and ending position of the subject within the string to be searched.
This allows for searching a sub-string without creating a slice of the string, which is advantageous for performance and also makes inroads for something like the
finditer
method.However, one caveat of using the start-pos rather than a slice is that the start anchor (
^
) remains anchored to the beginning of the text.