GO語言"regexp"包中"Match"函數的用法及代碼示例。
用法:
func Match(pattern string, b []byte)(matched bool, err error)
Match 報告字節片 b 是否包含正則表達式模式的任何匹配。更複雜的查詢需要使用 Compile 和完整的 Regexp 接口。
例子:
package main
import (
"fmt"
"regexp"
)
func main() {
matched, err := regexp.Match(`foo.*`, []byte(`seafood`))
fmt.Println(matched, err)
matched, err = regexp.Match(`bar.*`, []byte(`seafood`))
fmt.Println(matched, err)
matched, err = regexp.Match(`a(b`, []byte(`seafood`))
fmt.Println(matched, err)
}
輸出:
true <nil> false <nil> false error parsing regexp: missing closing ): `a(b`
相關用法
- GO MatchString用法及代碼示例
- GO Match用法及代碼示例
- GO MakeFunc用法及代碼示例
- GO Map用法及代碼示例
- GO MakeTable用法及代碼示例
- GO MarshalIndent用法及代碼示例
- GO Marshal用法及代碼示例
- GO MethodSet用法及代碼示例
- GO Mul32用法及代碼示例
- GO Mkdir用法及代碼示例
- GO MkdirTemp用法及代碼示例
- GO Modf用法及代碼示例
- GO Mul64用法及代碼示例
- GO Mod用法及代碼示例
- GO MultiReader用法及代碼示例
- GO MultiWriter用法及代碼示例
- GO Month用法及代碼示例
- GO MkdirAll用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Match。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。