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

Empty matches on replace/all #24

Closed
snan opened this issue May 13, 2021 · 6 comments
Closed

Empty matches on replace/all #24

snan opened this issue May 13, 2021 · 6 comments

Comments

@snan
Copy link
Contributor

snan commented May 13, 2021

(irregex-replace/all
 (irregex '(: bos (* whitespace)))
 "any gosh darn string" "")

⇒ "aany gosh darn string"

With a + instead of a kleenstar it works.

@ashinn
Copy link
Owner

ashinn commented May 14, 2021

0.9.7 fixed some corner cases involving empty matches, causing this regression. It's surprisingly tricky to get these all right - I'm half tempted to just throw errors on empty matches :(

@snan
Copy link
Contributor Author

snan commented May 14, 2021

Please do not throw errors on empty matches!

@ashinn
Copy link
Owner

ashinn commented May 14, 2021

I'm just grumbling and kicking myself for fixing the symptoms of the empty matches previously instead of the root cause.

@snan
Copy link
Contributor Author

snan commented May 14, 2021

What I did for loop detection was to stop when we were string=? to the previous iter. That has turned out to be super expensive though.

@ashinn
Copy link
Owner

ashinn commented May 14, 2021

Just use irregex-fold for iteration, it does the work for you.

@snan
Copy link
Contributor Author

snan commented May 14, 2021

I do use irregex-fold in another place in the code. The case where I used string=? for loop detection was for recursive re-matching from the start of the string. I.e. (strse "aaaaaaaah!" "aa" "a" #t) ⇒ "ah!" This isn't something irregex-fold is set up to do since it uses consecutive matching on the original string. Also, irregex-fold/fast isn't exported as far as I could tell so the way to use it is to use replace/all, which is what my "aaaaaah" thing does: calls replace/all again and again until it's satisfied.

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

2 participants