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

Regular Expressions: replacing empty patterns only works correctly in nre #9306

Closed
skilchen opened this issue Oct 11, 2018 · 4 comments
Closed

Regular Expressions: replacing empty patterns only works correctly in nre #9306

skilchen opened this issue Oct 11, 2018 · 4 comments
Labels

Comments

@skilchen
Copy link
Contributor

@skilchen skilchen commented Oct 11, 2018

Using nre:

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

produces:

foobar
foobar
-f-o-o-

as expected.

Using re instead:

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

each replace ends in an infinite loop.

And @nitely's Module regex

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

produces:

foobfooafoor
fobarbarbarfoo
-f-o-o

which doesn't make much sense... But this is not a Nim issue.

@Araq
Copy link
Member

@Araq Araq commented Oct 11, 2018

Endless loops are just as fine here IMO, garbage in, garbage out.

@kaushalmodi
Copy link
Contributor

@kaushalmodi kaushalmodi commented Oct 11, 2018

I ended up on re replace entering an endless loop just yesterday, for a simple toy example:

import re 
echo replace("hello", re"$", "!") # expected "hello!", but inflooped

@kaushalmodi
Copy link
Contributor

@kaushalmodi kaushalmodi commented Oct 11, 2018

Endless loops are just as fine here IMO, garbage in, garbage out.

I didn't follow.

@skilchen
Copy link
Contributor Author

@skilchen skilchen commented Oct 11, 2018

@Araq

Endless loops are just as fine here IMO, garbage in, garbage out.

Neither the empty string nor zero-length matches are garbage.

@Araq Araq closed this in 8ab6fa1 Oct 11, 2018
Araq added a commit that referenced this issue Oct 14, 2018
krux02 added a commit to krux02/Nim that referenced this issue Oct 15, 2018
krux02 added a commit to krux02/Nim that referenced this issue Oct 15, 2018
narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018
narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018
narimiran added a commit to narimiran/Nim that referenced this issue Nov 1, 2018
narimiran added a commit to narimiran/Nim that referenced this issue Nov 1, 2018
narimiran added a commit that referenced this issue Nov 1, 2018
narimiran added a commit that referenced this issue Nov 1, 2018
(cherry picked from commit 8ab6fa1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants