match

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT, MIT Imports: 1 Imported by: 0

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 returns true if str matches pattern. This is a very simple wildcard match where '*' matches on any number characters and '?' matches on any one character.

pattern:

{ term }

term:

'*'         matches any sequence of non-Separator characters
'?'         matches any single non-Separator character
c           matches character c (c != '*', '?', '\\')
'\\' c      matches character c

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

func MatchLimit

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

MatchLimit is the same as Match but will limit the complexity of the match operation. This is to avoid long running matches, specifically to avoid ReDos attacks from arbritary inputs.

How it works: The underlying match routine is recursive and may call itself when it encounters a sandwiched wildcard pattern, such as: `user:*:name`. Everytime it calls itself a counter is incremented. 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. Such that string "Hello World" with match with lower case pattern "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