package main
import (
"fmt"
"regexp"
"sync"
)
func main() {
r := "^(?P<a>x){1,3}(?P<b>123){0,2}(?P<a>x){1,3}$"
getParams(r, "xxx")
}
// Regex store complier
var Regex sync.Map
func getParams(regEx, str string) (paramsMap map[string][]string) {
var compRegEx *regexp.Regexp
tmp, ok := Regex.Load(regEx)
if !ok {
compRegEx = regexp.MustCompile(regEx)
Regex.Store(regEx, compRegEx)
} else {
// panic
compRegEx, ok = tmp.(*regexp.Regexp)
if !ok {
return nil
}
}
match := compRegEx. FindStringSubmatch(str)
if len(match) == 0 {
return nil
}
fmt.Println(match)
return nil
}
my question is:
how to determine the number of matches of “x” ,the first regix mode “(?Px){1,3}” matched quantity how much?and the second the mode “(?Px){1,3}” get how much?
i dont konw how to determine。who can tell me ?thank you very much