Created
March 24, 2017 02:43
-
-
Save sundy-li/aa9849aba93b3ac5e2ddb9f0bcb1c21a to your computer and use it in GitHub Desktop.
regexp_namedgroup.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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