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.

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

报告相同问题?