mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2024-12-13 18:11:25 +01:00
20 lines
345 B
Go
20 lines
345 B
Go
|
package lib
|
||
|
|
||
|
import "regexp"
|
||
|
|
||
|
func MatchCaptureGroup(pattern, payload string) map[string]string {
|
||
|
patterns := make(map[string]string)
|
||
|
|
||
|
expr := regexp.MustCompile(pattern)
|
||
|
|
||
|
match := expr.FindStringSubmatch(payload)
|
||
|
|
||
|
for i, name := range expr.SubexpNames() {
|
||
|
if i != 0 && name != "" {
|
||
|
patterns[name] = match[i]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return patterns
|
||
|
}
|