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

Unexpected replacements for "^", "$", "" #29

Closed
kaushalmodi opened this issue Oct 11, 2018 · 3 comments · Fixed by #63 or #65
Closed

Unexpected replacements for "^", "$", "" #29

kaushalmodi opened this issue Oct 11, 2018 · 3 comments · Fixed by #63 or #65

Comments

@kaushalmodi
Copy link
Contributor

See nim-lang/Nim#9306.

import regex
echo replace("bar", re"^", "foo")
echo replace("foo", re"$", "bar")
echo replace("foo", re"", "-")

produces:

foobfooafoor # expected: foobar
fobarbarbarfoo # expected: foobar
-f-o-o # expected: -f-o-o-
@timotheecour
Copy link
Contributor

timotheecour commented Oct 11, 2018

as mentioned in nim-lang/Nim#9306 (comment) what nre does here seems correct, and what nim-regex should do

Using nre:

import nre
echo replace("bar", re"^", "foo")
echo replace("foo", re"$", "bar")
echo replace("foo", re"", "-")
produces:

foobar
foobar
-f-o-o-

@nitely
Copy link
Owner

nitely commented Oct 11, 2018

I think this a duplicate of #13. I'll try to fix it (again) this weekend soon. IIRC, it's not as easy as implementing the nre version of this function, there is some issue in how empty matches are handled.

@kaushalmodi
Copy link
Contributor Author

Thank you!!

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.

3 participants