mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-13 07:46:56 +08:00
25 lines
587 B
Go
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)
|
|
}
|