📗Go语言:基础大全

Go语言:识别路径是否正确(支持通配符)

2019-11-17  本文已影响0人  白祤星

备注:


通配符 说明
? 匹配一个任意的字符
* 匹配无限个任意的字符,包括没有字符

代码实例:


package main

import (
    "fmt"
    "path/filepath"
)

func main() {
    // 识别路径,完全匹配时返回 true
    fmt.Println(filepath.Match(`?`, `a`))     // true
    fmt.Println(filepath.Match(`?`, `aa`))    // false
    fmt.Println(filepath.Match(`a?`, `aa`))   // true
    fmt.Println(filepath.Match(`??`, `aa`))   // true
    fmt.Println(filepath.Match(`*`, ``))      // true
    fmt.Println(filepath.Match(`*`, `a/b/c`)) // true
    fmt.Println(filepath.Match(`//b`, `b`))   // false
}
上一篇 下一篇

猜你喜欢

热点阅读