GO語言"path"包中"Match"函數的用法及代碼示例。
用法:
func Match(pattern, name string)(matched bool, err error)
Match 報告 name 是否與 shell 模式匹配。模式語法是:
pattern:
{ term }
term:
'*' matches any sequence of non-/ characters
'?' matches any single non-/ character
'[' [ '^' ] { character-range } ']'
character class (must be non-empty)
c matches character c (c != '*', '?', '\\', '[')
'\\' c matches character c
character-range:
c matches character c (c != '\\', '-', ']')
'\\' c matches character c
lo '-' hi matches character c for lo <= c <= hi
匹配需要模式來匹配所有名稱,而不僅僅是一個子字符串。當模式格式錯誤時,唯一可能返回的錯誤是ErrBadPattern。
例子:
package main
import (
"fmt"
"path"
)
func main() {
fmt.Println(path.Match("abc", "abc"))
fmt.Println(path.Match("a*", "abc"))
fmt.Println(path.Match("a*/b", "a/c/b"))
}輸出:
true <nil> true <nil> false <nil>
相關用法
- GO MatchString用法及代碼示例
- 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大神的英文原創作品 Match。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
