go正则表达式

func decodeString2(s string) string {
    res:=regexp.MustCompile("\\d+\\[\\w+]")
    res2:=regexp.MustCompile("\\d+")
    res3:=regexp.MustCompile("\\[\\w+]")
    for res.MatchString(s){
        s = res.ReplaceAllStringFunc(s, func(tes string) string {
            var temp strings.Builder
            nums, _ := strconv.Atoi(res2.FindAllString(tes, -1)[0])
            words := res3.FindAllString(tes, -1)[0]
            word := words[1 : len(words)-1]
            for i := 0; i < nums; i++ {
                temp.WriteString(word)
            }
            return temp.String()
        })
    }
    return s
}

你可能感兴趣的:(go正则表达式)