mirror of
https://github.com/anchore/grype
synced 2024-11-10 14:44:12 +00:00
0a9408005f
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
15 lines
439 B
Go
15 lines
439 B
Go
package internal
|
|
|
|
import "regexp"
|
|
|
|
// MatchCaptureGroups takes a regular expression and string and returns all of the named capture group results in a map.
|
|
func MatchCaptureGroups(regEx *regexp.Regexp, str string) map[string]string {
|
|
match := regEx.FindStringSubmatch(str)
|
|
results := make(map[string]string)
|
|
for i, name := range regEx.SubexpNames() {
|
|
if i > 0 && i <= len(match) {
|
|
results[name] = match[i]
|
|
}
|
|
}
|
|
return results
|
|
}
|