Created
June 12, 2017 12:15
-
-
Save crgimenes/f05230e8ca290c2aa7bc95fbfd7efd55 to your computer and use it in GitHub Desktop.
Simple regex submatch function example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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