Golang正则表达式报价子匹配

I am trying to extract a submatch value from a regexp but to all for it to disregard a set of quotes if necessary. So far I have this:

url: http://play.golang.org/p/lcKLKmi1El

package main

import "fmt"
import "regexp"

func main() {
  authRegexp := regexp.MustCompile("^token=(?:\"(.*)\"|(.*))$")

  matches := authRegexp.FindStringSubmatch("token=llll")
  fmt.Println("MATCHES", matches, len(matches))

  matches = authRegexp.FindStringSubmatch("token=\"llll\"")
  fmt.Println("MATCHES", matches, len(matches))
}

Input::Expected Matches

token=llll::[token=llll llll]

token="llll"::[token="llll" llll]

Also note that I want to test for either no quotes, or a single set of quotes. I don't want to be able to have mismatched quotes or anything.

How do I get rid of the empty string that is returned? Is there a better regex to get rid of the quotes?

Ok, that's it: http://play.golang.org/p/h2w-9-XFAt

Regex: ^token="?([^"]*)"?$

MATCHES [token=llll llll] 2
MATCHES [token="llll" llll] 2

Try the following:

authRegexp := regexp.MustCompile("^token=(.*?|\".*?\")$")
Demo here.