duanbipu1720 2012-04-23 15:54
浏览 597
已采纳

在Regexp.FindAllStringSubmatch()中,第二个参数做什么?

In this method:

func (re *Regexp) FindAllStringSubmatch(s string, n int) [][]string

What does the second parameter do? I have tried:

re, _ := regexp.Compile("a")
rs := re.FindAllString("aaaaa, ", **1**) // 1 get one 'a', 2 get two 'a's, 3 get three 'a's ...
for _,v := range rs {
    fmt.Println(v)

}

It seems that the second parameter is about how many times it matches. Am I right? Could anybody give me an answer for sure? Official doc or some links is prefer.

  • 写回答

1条回答 默认 最新

  • dquoj04882 2012-04-23 16:08
    关注

    Citation from the overview section of http://golang.org/pkg/regexp/:

    If 'All' is present, the routine matches successive non-overlapping matches of the entire expression. Empty matches abutting a preceding match are ignored. The return value is a slice containing the successive return values of the corresponding non-'All' routine. These routines take an extra integer argument, n; if n >= 0, the function returns at most n matches/submatches.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器