正则表达式

    b := []byte("abc1def1")
    pat := `abc1|abc1def1`
    reg1 := regexp.MustCompile(pat)      // 第一匹配
    reg2 := regexp.MustCompilePOSIX(pat) // 最长匹配
    fmt.Printf("%s\n", reg1.Find(b))     // abc1
    fmt.Printf("%s\n", reg2.Find(b))     // abc1def1

 

posted @ 2020-04-10 11:08  柠檬abcd  阅读(123)  评论(0编辑  收藏  举报