File: regexp.go

package info (click to toggle)
tiup 1.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,384 kB
  • sloc: sh: 1,988; makefile: 138; sql: 16
file content (14 lines) | stat: -rw-r--r-- 369 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package utils

import "regexp"

// MatchGroups turns a slice of matched string to a map according to capture group name
func MatchGroups(r *regexp.Regexp, str string) map[string]string {
	matched := r.FindStringSubmatch(str)
	results := make(map[string]string)
	names := r.SubexpNames()
	for i, value := range matched {
		results[names[i]] = value
	}
	return results
}