Skip to content

nikole-dunixi/regexmap

Repository files navigation

regexmap

Very simple and straight forward function to take a regex and, for all given named matches, populate a map.

Installation

$ go get github.com/nikole-dunixi/regexmap

Usage

Suppose 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

API

regexmap.MatchPattern(r string, s string) (map[string]string, error)

  • 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.

regexmap.MatchRegex(r *regexp.Regexp, s string) (map[string]string, 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.

License

MIT and Apache License. See LICENSE-APACHE and LICENSE-MIT for details.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published