Regexp FindAll with n=0 returns nothing

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: go-best-practices/regexp-zero-results

Language: Go

Severity: Info

Category: Best Practices

Description

Go, invoking the function re.FindAll() with the second argument set to 0 will not return any results.

Non-Compliant Code Examples

import "regexp"

func main () {
    re := regexp.MustCompile("foo(")
    re.FindAll([]byte(`seafood fool`), 0)
}
import "regexp"

func main () {

    var re *regexp.Regexp

    res := re.FindAll(something, 0)
}
import "regexp"

func main () {

    re := regexp.MustCompile(`foo.?`)

    res := re.FindAll(something, 0)
}
import "regexp"

func main () {
    var r *regexp.Regexp
    res := r.FindAll(something, 0)
    
    var r2 regexp.Regexp
    res := r2.FindAll(something, 0)

    regexp.MustCompile("foo(").FindAll(nil, 0)
    regexp.MustCompile(`foo.?`).FindAll([]byte(`seafood fool`), -1)

    res = r.FindAll(something, 0)

    if something {
        re.FindAll([]byte(`seafood fool`), -1)
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis