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
Labels

Comments

@skilchen
Copy link
Contributor

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 commented Oct 11, 2018

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

@kaushalmodi
Copy link
Contributor

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

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

I didn't follow.

@skilchen
Copy link
Contributor Author

@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 as completed in 8ab6fa1 Oct 11, 2018
Araq added a commit that referenced this issue Oct 14, 2018
krux02 pushed a commit to krux02/Nim that referenced this issue Oct 15, 2018
krux02 pushed a commit to krux02/Nim that referenced this issue Oct 15, 2018
narimiran pushed a commit to narimiran/Nim that referenced this issue Oct 31, 2018
narimiran pushed a commit to narimiran/Nim that referenced this issue Oct 31, 2018
narimiran pushed a commit to narimiran/Nim that referenced this issue Nov 1, 2018
narimiran pushed a commit to narimiran/Nim that referenced this issue Nov 1, 2018
narimiran pushed a commit that referenced this issue Nov 1, 2018
narimiran pushed 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
Development

No branches or pull requests

4 participants