mark2web/pkg/helper/regexp.go
Sebastian Frank ff1da084af
All checks were successful
continuous-integration/drone/push Build is passing
collections via markdown files
2019-03-22 17:22:03 +01:00

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
}