match

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT, MIT Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package match provides a simple pattern matcher with unicode support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Allowable

func Allowable(pattern string) (min, max string)

Allowable parses the pattern and determines the minimum and maximum allowable values that the pattern can represent. When the max cannot be determined, 'true' will be returned for infinite.

func IsPattern

func IsPattern(str string) bool

IsPattern returns true if the string is a pattern.

func Match

func Match(str, pattern string) bool

Match 判断 str 是否匹配 pattern; '*' 匹配任意字符序列, '?' 匹配任意单个字符.

pattern:

{ term }

term:

'*'         匹配任意字符序列, 包括路径分隔符
'?'         匹配任意单个字符, 包括路径分隔符
c           matches character c (c != '*', '?', '\\')
'\\' c      matches character c

默认保持大小写敏感, 不对匹配复杂度设置上限.

func MatchLimit

func MatchLimit(str, pattern string, maxcomp int) (matched, stopped bool)

MatchLimit 与 Match 类似, 但会限制匹配复杂度, 避免任意输入造成长时间匹配或 ReDoS 攻击.

How it works: The underlying match routine is recursive and may call itself when it encounters a sandwiched wildcard pattern, such as: `user:*:name`. 每次递归调用都会增加计数器. The operation is stopped when counter > maxcomp*len(str). 大小写敏感匹配与忽略大小写入口共用预算规则, 超限时通过 stopped 标识.

func MatchLimitNoCase added in v1.3.7

func MatchLimitNoCase(str, pattern string, maxcomp int,
) (matched, stopped bool)

MatchLimitNoCase 使用与 MatchLimit 相同的复杂度预算, 仅忽略 ASCII 字母大小写. 超出预算时返回 stopped, 调用方应将其与普通不匹配区分.

func MatchNoCase added in v1.3.7

func MatchNoCase(str, pattern string) bool

MatchNoCase is the same as Match but performs a case-insensitive match. 例如, 字符串 "Hello World" 可以匹配小写模式 "hello*". 仅忽略 ASCII 字母大小写, 其他 Unicode 字符仍按原值匹配.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL