Created
August 20, 2019 04:48
-
-
Save miguelmota/9b1d77c7e68320bba0dc0763372f7202 to your computer and use it in GitHub Desktop.
Golang find string sub groups match using regex
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
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