diff options
Diffstat (limited to 'pkg/utils/regexp.go')
-rw-r--r-- | pkg/utils/regexp.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/utils/regexp.go b/pkg/utils/regexp.go new file mode 100644 index 000000000..2ceab1d71 --- /dev/null +++ b/pkg/utils/regexp.go @@ -0,0 +1,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 +} |