Go语言实践Go

Golang正则匹配成对的括号

2019-07-03  本文已影响2人  承诺一时的华丽

Test

func TestGetVaild(t *testing.T)  {
    str:="zxtestcv,Vaild[Email;Min(120)]()][fdwd]"
    var reg = regexp.MustCompile(`Vaild\[(.*?)]`)
    params:=reg.FindStringSubmatch(str)
    for _,param :=range params {
        t.Log(param)
    }
}

测试结果:

=== RUN   TestGetVaild
--- PASS: TestGetVaild (0.00s)
    utils_test.go:16: Vaild[Email;Min(120)]
    utils_test.go:16: Email;Min(120)
PASS

Process finished with exit code 0
上一篇 下一篇

猜你喜欢

热点阅读