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

replace seems to be greedy even with few #44

Open
jtojnar opened this issue Dec 15, 2021 · 1 comment
Open

replace seems to be greedy even with few #44

jtojnar opened this issue Dec 15, 2021 · 1 comment

Comments

@jtojnar
Copy link
Contributor

jtojnar commented Dec 15, 2021

> replace ("x" <$ string "/*" <* few anySym <* string "*/") "1 /* foo */ 2 /* bar */ 3"
"1 x 3"

Whereas I would expect 1 x 2 x 3 as a result.

Replacing findLongestInfix by findFirstInfix in replace definition seems to fix this case but I am not sure if this is a proper solution.

Using regex-applicative-0.3.4

@UnkindPartition
Copy link
Owner

I think you are correct. Would you care to prepare a PR?

Just in case someone is relying on the old behavior, let's introduce the corrected version under a new name (say, replace2) and add a DEPRECATED pragma on the old one. And please add the tests for both greedy and non-greedy regexes. (Perhaps even add doctests?)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants