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

Lazy Modifier ? Works Incorrectly in Capture Groups #21

Open
brodieG opened this issue Jun 19, 2014 · 0 comments
Open

Lazy Modifier ? Works Incorrectly in Capture Groups #21

brodieG opened this issue Jun 19, 2014 · 0 comments
Labels

Comments

@brodieG
Copy link

brodieG commented Jun 19, 2014

This is using the library included in R 3.0.2:

text <- "abcdEEEEfg"

sub("c.+?E", "###", text)
# [1] "ab###EEEfg"                          <<< OKAY
sub("c(.+?)E", "###", text)
# [1] "ab###EEfg"                           <<< WEIRD
sub("c(.+?)E", "###", text, perl=T)
# [1] "ab###EEEfg"                          <<< OKAY

Notice how in the second example something very odd is happening. The capture is neither greedy nor lazy. It should be lazy and look like the first and third examples, but if it were greedy it would capture one more E than it did.

This is almost certainly related to issue 11, but posting it separately as they issue description is not quite the same.

Also, original post on SO for reference with some more details.

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

2 participants