Files
cloudpods/pkg/util/regutils2/regutils.go
T
2019-01-14 16:44:01 +08:00

25 lines
587 B
Go

package regutils2
import "regexp"
/**
* Parses val with the given regular expression and returns the
* group values defined in the expression.
*/
func GetParams(compRegEx *regexp.Regexp, val string) map[string]string {
match := compRegEx.FindStringSubmatch(val)
paramsMap := make(map[string]string, 0)
for i, name := range compRegEx.SubexpNames() {
if i > 0 && i <= len(match) {
paramsMap[name] = match[i]
}
}
return paramsMap
}
func SubGroupMatch(pattern string, line string) map[string]string {
regEx := regexp.MustCompile(pattern)
return GetParams(regEx, line)
}