Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Created June 12, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crgimenes/f05230e8ca290c2aa7bc95fbfd7efd55 to your computer and use it in GitHub Desktop.
Save crgimenes/f05230e8ca290c2aa7bc95fbfd7efd55 to your computer and use it in GitHub Desktop.
Simple regex submatch function example
func FindSubmatch(text string, regex string, submatch int) (ret string) {
var r = regexp.MustCompile(regex)
a := r.FindStringSubmatch(text)
if len(a) <= submatch {
ret = ""
return
}
ret = a[submatch]
ret = strings.TrimSpace(ret)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment