summaryrefslogtreecommitdiffstats
path: root/pkg/utils/regexp.go
blob: 2ceab1d719b04950271d3d13915a18d6b81cab99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package utils

import "regexp"

func FindNamedMatches(regex *regexp.Regexp, str string) map[string]string {
	match := regex.FindStringSubmatch(str)

	if len(match) == 0 {
		return nil
	}

	results := map[string]string{}
	for i, value := range match[1:] {
		results[regex.SubexpNames()[i+1]] = value
	}
	return results
}