diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-26 15:56:05 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-26 16:48:23 +1100 |
commit | 7bc8b96abaf54a5f7c5149c8ebc4e0d5bb16ab09 (patch) | |
tree | 7bb9a3f0bbc077eea0441a7a8e5edde31de73adf /pkg/utils/regexp.go | |
parent | 38743ec99fafb6b093c1f5d117c9bcaa708dbcde (diff) |
add FindNamedMatches function in utils
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 +} |