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

regexp: greedy matching right-to-left vs left-to-right #110

Closed
gopherbot opened this issue Nov 12, 2009 · 5 comments
Closed

regexp: greedy matching right-to-left vs left-to-right #110

gopherbot opened this issue Nov 12, 2009 · 5 comments
Assignees

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 12, 2009

by stefanha:

regexp.MatchStrings() produces unexpected results which suggest that greedy
matching works right-to-left.  Conventional regular expression engines seem
to match left-to-right (sed, Vim, Perl, Python, ...).

The documentation does not state the intended behavior.  If it really
should work right-to-left, then a note in the documentation would help
reduce surprise.

What steps will reproduce the problem?
1. See the following test program:

package main

import "regexp"
import "fmt"

func main() {
        re, _ := regexp.Compile("(.*).*");
        a := re.MatchStrings("this is a test");
        fmt.Printf("%#v\n", a);
}

2. The following output is produced:

[]string{"this is a test", ""}

The .* outside of a group has matched the line.  I expect greedy matching
to work left-to-right, therefore the (.*) should match the line:

[]string{"this is a test", "this is a test"}

What is your $GOOS?  $GOARCH?

GOOS=linux GOARCH=386

Which revision are you sync'ed to?  (hg log -l 1)

3975:b51fd2d6c160

Simple comparisons:

$ echo this is a test | sed 's/\(.*\).*/\1/'
this is a test

$ python -c 'import re; print re.match("(.*).*", "this is a
test").groups()'
('this is a test',)
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Nov 12, 2009

Comment 1 by stefanha:

Apologies for the silly issue title, I pressed submit too early.  I cannot see a way
to edit the title.
@agl
Copy link
Contributor

@agl agl commented Nov 12, 2009

Comment 2:

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Nov 12, 2009

Comment 3:

Owner changed to r...@golang.org.

Status changed to LongTerm.

@robpike
Copy link
Contributor

@robpike robpike commented Nov 14, 2009

Comment 4:

This issue was closed by revision 0263103.

Status changed to Fixed.

Merged into issue #-.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Nov 14, 2009

Comment 5 by stefanha:

Thank you for fixing this!
@gopherbot gopherbot added the fixed label Nov 14, 2009
minux added a commit to minux/goios that referenced this issue Feb 27, 2015
liblink for ppc64x contains a rule for "NEG ,Rn" to mean "NEG Rn, Rn",
but arm64 doesn't have such a rule.

Fixes golang#110.
minux added a commit to minux/goios that referenced this issue Feb 27, 2015
liblink for ppc64x contains a rule for "NEG ,Rn" to mean "NEG Rn, Rn",
but arm64 doesn't have such a rule.

Fixes golang#110.
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.