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

Setting optional group uses wrong offset #14

Open
tek opened this issue Mar 14, 2023 · 0 comments
Open

Setting optional group uses wrong offset #14

tek opened this issue Mar 14, 2023 · 0 comments

Comments

@tek
Copy link

tek commented Mar 14, 2023

This appears to be similar to #7, but since it happens in 1.1.0.0, I thought you might have overlooked something.

ghci> "aaxxc" & [regex|aax(b)?x(c)|] . group 0 .~ "B"
"Baaxxc"
ghci> "aaxxc" & [regex|(aa)x(b)?x(c)|] . group 1 .~ "B"
"aaBxxc"

When the optional group is the last one, nothing is changed:

ghci> "aaxxc" & [regex|(aa)x(b)?xc|] . group 1 .~ "B"
"aaxxc"

Like in the other issue, making the optional group non-capturing and wrapping it in a new group works around the issue:

ghci> "aaxxc" & [regex|(aa)x((?:b)?)xc|] . group 1 .~ "B"
"aaxBxc"

No worries if this is too awkward to implement reliably, the workaround is tolerable 🙂

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

No branches or pull requests

1 participant