Very simple and straight forward function to take a regex and, for all given named matches, populate a map.
$ go get github.com/nikole-dunixi/regexmapSuppose you want to extract named groups from a string using a regular expression:
input := `Nikole Dunixi`
pattern := `^(?P<first>\w+)\s+(?P<last>\w+)$`
// err ignored for brevity
matches, _ := regexmap.MatchPattern(pattern, input)
fmt.Println(matches["first"], matches["last"])
// Output:
// Nikole Dunixi- r: A regular expression string with named capturing groups.
- s: The string to match against.
- Returns: A map of group names to their matched values, or an error.
- r: A compiled regex with named capture groups.
- s: The string to match against.
- Returns: A map of group names to their matched values, or an error.
MIT and Apache License. See LICENSE-APACHE and LICENSE-MIT for details.