19 lines
451 B
Go
19 lines
451 B
Go
package helper
|
|
|
|
import "regexp"
|
|
|
|
// GetRegexpParams gets a map of named regexp group matches
|
|
// use pe. (?P<Year>\d{4})-(?P<Month>\d{2})-(?P<Day>\d{2}) as regexp
|
|
func GetRegexpParams(regEx *regexp.Regexp, str string) (paramsMap map[string]string) {
|
|
|
|
match := regEx.FindStringSubmatch(str)
|
|
|
|
paramsMap = make(map[string]string)
|
|
for i, name := range regEx.SubexpNames() {
|
|
if i > 0 && i <= len(match) {
|
|
paramsMap[name] = match[i]
|
|
}
|
|
}
|
|
return
|
|
}
|