2012-04-23 15:54
浏览 332


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 {


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.

图片转代码服务由CSDN问答提供 功能建议


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

第二个参数做什么? 我尝试过:

  re,_:= regexp.Compile(“ a”)
rs:= re.FindAllString(“ aaaaa,”,** 1 **)// 1得一个'a',2得两个 'a's,3得到三个'a's ... 
for _,v:= range rs {

似乎第二个参数是关于它匹配多少次的信息。 我说得对吗? 有人可以肯定地给我答案吗? 首选官方文档或一些链接。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题