GO語言"regexp"包中"MatchString"函數的用法及代碼示例。
用法:
func MatchString(pattern string, s string)(matched bool, err error)
MatchString 報告字符串 s 是否包含正則表達式模式的任何匹配項。更複雜的查詢需要使用 Compile 和完整的 Regexp 接口。
例子:
package main
import (
"fmt"
"regexp"
)
func main() {
matched, err := regexp.MatchString(`foo.*`, "seafood")
fmt.Println(matched, err)
matched, err = regexp.MatchString(`bar.*`, "seafood")
fmt.Println(matched, err)
matched, err = regexp.MatchString(`a(b`, "seafood")
fmt.Println(matched, err)
}
輸出:
true <nil> false <nil> false error parsing regexp: missing closing ): `a(b`
相關用法
- 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用法及代碼示例
- GO LeadingZeros32用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 MatchString。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。