Skip to content

Instantly share code, notes, and snippets.

@sundy-li
Created March 24, 2017 02:43
Show Gist options
  • Save sundy-li/aa9849aba93b3ac5e2ddb9f0bcb1c21a to your computer and use it in GitHub Desktop.
Save sundy-li/aa9849aba93b3ac5e2ddb9f0bcb1c21a to your computer and use it in GitHub Desktop.
regexp_namedgroup.go
package main
import (
"fmt"
"regexp"
)
var myExp = regexp.MustCompile(`(?P<first>\d+)\.(\d+).(?P<second>\d+)`)
func main() {
fmt.Printf("%+v", myExp.FindStringSubmatch("1234.5678.9"))
match := myExp.FindStringSubmatch("1234.5678.9")
for i, name := range myExp.SubexpNames() {
fmt.Printf("'%s'\t %d -> %s\n", name, i, match[i])
}
//fmt.Printf("by name: %s %s\n", match["first"], match["second"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment