Closed
Description
http://play.golang.org/p/n5XbC7kTDt
package main
import (
"fmt"
"regexp"
)
func main() {
s := "abc"
rePass := regexp.MustCompile("(a.*?c)|a.*?b")
reFail := regexp.MustCompile("a.*?c|a.*?b")
fmt.Printf("%v\n", rePass.FindStringIndex(s))
// Writes "[0 3]"
fmt.Printf("%v\n", reFail.FindStringIndex(s))
// Writes "[0 2]"
}
The overall match found should not depend on capturing parens. In this case, the a.*?c
branch of the alternative should take priority over the a.*?b
branch in both expressions, so both should match [0 3] not [0 2].
This happens in C++ RE2 as well.