实现自增功能,00001两边有值。
123aaaaa00001_a
123aaaaa00002_a
123aaaaa00003_a
str:="123aaaaa00001_a"
var valid = regexp.MustCompile("[0-9]*[0-9]")
a0 := valid.FindAllString(str, -1)
a1 := valid.FindAllStringIndex(str, -1)
start := fmt.Sprintf(str[:a1[len(a0)-1][0]])
end := fmt.Sprintf(str[a1[len(a0)-1][1]:])
ss, _ := strconv.ParseInt(a0[len(a0)-1], 10, 64)
x:=[5]int{1,2,3,4,5}
for k, _ := range x{
sss := fmt.Sprintf("%0*d", len(a0[len(a0)-1]), ss+int64(k))
fmt.Println( start + sss + end)
}
有疑问加站长微信联系(非本文作者)