Skip to content
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

<regex>: Properly parse dollar anchors in basic and grep mode #5362

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

muellerj2
Copy link
Contributor

This PR provides the symmetric change to #5165 for the dollar sign in basic and grep mode. Similar to the handling of the caret anchor, this PR recognizes a dollar sign as an anchor in a basic regular expression if it is at the end of an alternative. It does so by doing a bit of lookahead.

Drive-by: Remove a duplicated test that was accidentally added in #5165.

@muellerj2 muellerj2 requested a review from a team as a code owner March 25, 2025 19:24
Comment on lines +3951 to +3955
const bool _Is_end_of_alternative =
((_L_flags & _L_alt_pipe) && _Ch == _Meta_bar) // dollar followed by pipe |
|| ((_L_flags & _L_alt_nl) && _Ch == _Meta_nl && _Disj_count == 0) // dollar followed by pipe \n
|| ((_Escaped || (_L_flags & _L_nex_grp)) && _Ch == _Meta_rpar
&& _Disj_count != 0); // dollar followed by parenthesis closing a group
Copy link
Contributor Author

@muellerj2 muellerj2 Mar 25, 2025

Choose a reason for hiding this comment

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

Strictly speaking, _L_flags & _L_alt_pipe and _L_flags & _L_nex_grp are always 0 here, so the first disjunct could be removed completely and _L_flags & _L_nex_grp could be omitted in the third.

I still opted for this expression, though, because it clearly handles all possible cases of "end of an alternative", independent of how the flags for alternatives correlate in practice with the flag _L_anch_rstr.

@StephanTLavavej StephanTLavavej added bug Something isn't working regex meow is a substring of homeowner labels Mar 25, 2025
@StephanTLavavej StephanTLavavej self-assigned this Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regex meow is a substring of homeowner
Projects
Status: Initial Review
Development

Successfully merging this pull request may close these issues.

2 participants