I was trying to use regexp to do some pattern matching with the or operator but I got some odd results. I have stripped out everything but the essentials to show the problem with my result.
This is my code:
package main
- import "fmt"
- import "regexp"
-
- func main() {
- authRegexp := regexp.MustCompile("^token=(llll|(.+))$")
- matches := authRegexp.FindStringSubmatch("token=llll")
- fmt.Println("MATCHES", matches, len(matches))
- // MATCHES [token=llll llll ] 3
- }
Url: http://play.golang.org/p/nLtWQQgveY
The matches array has a length of 3, when I think it should have a length of 2. The last value is an empty string. I dont understand why it does this. Is this a golang bug? How do I submit golang bugs?