Need to split something like 1-(a+b-b-d)*100 into 1, a+b-b-d, 100
I tried (\+|-|\*|\/)
which will split the string into 1 (a b b d) 100
Need to split something like 1-(a+b-b-d)*100 into 1, a+b-b-d, 100
I tried (\+|-|\*|\/)
which will split the string into 1 (a b b d) 100
regular expression pattern:
^(\d+?)\-(\(.+?\))\*(\d+?)$
package main
import (
"log"
"regexp"
)
func main() {
reg := regexp.MustCompile(`^(\d+?)\-(\(.+?\))\*(\d+?)$`)
str := `1-(a+b-b-d)*100`
// see: https://pkg.go.dev/regexp#Regexp.FindAllSubmatch
ret := reg.FindAllSubmatch([]byte(str), -1)
log.Printf("%s %s %s", ret[0][1], ret[0][2], ret[0][3])
}