Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created August 20, 2019 04:48
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 miguelmota/9b1d77c7e68320bba0dc0763372f7202 to your computer and use it in GitHub Desktop.
Save miguelmota/9b1d77c7e68320bba0dc0763372f7202 to your computer and use it in GitHub Desktop.
Golang find string sub groups match using regex
package main
import (
"fmt"
"regexp"
)
func main() {
regex := regexp.MustCompile(`^([0-9]+)|([a-z]+)$`)
matches := regex.FindAllString("100mb", -1)
fmt.Println(matches[0]) // 100
fmt.Println(matches[1]) // mb
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment