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

Comments

Projects
None yet
4 participants
@skilchen
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

Araq commented Oct 11, 2018

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

@kaushalmodi

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

kaushalmodi commented Oct 11, 2018

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

I didn't follow.

@skilchen

This comment has been minimized.

Copy link
Contributor

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

@timotheecour timotheecour added the regex label Oct 29, 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

fixes #9306
(cherry picked from commit 8ab6fa1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment