Documentation
¶
Overview ¶
Package fastregex provides a thin wrapper around regexp.Regexp that auto-detects simple pattern shapes and dispatches to faster string operations instead of running the full regex automaton.
Detection uses regexp/syntax to inspect the parsed AST.
Recognised fast paths:
^literal$ → string equality (==) ^literal → strings.HasPrefix ^literal.*$ → strings.HasPrefix ^.*literal$ → strings.HasSuffix literal$ → strings.HasSuffix literal → strings.Contains ^.*literal.*$ → strings.Contains ^literal.*literal$ → strings.HasPrefix && strings.HasSuffix
Everything else falls back to regexp.Regexp.MatchString.
Package fastregex provides a thin wrapper around regexp.Regexp that auto-detects simple pattern shapes and dispatches to faster string operations instead of running the full regex automaton.
Detection uses regexp/syntax to inspect the parsed AST.
Recognised fast paths:
^literal$ → string equality (==) ^literal → strings.HasPrefix ^literal.*$ → strings.HasPrefix ^.*literal$ → strings.HasSuffix literal$ → strings.HasSuffix literal → strings.Contains ^.*literal.*$ → strings.Contains ^literal.*literal$ → strings.HasPrefix && strings.HasSuffix
Everything else falls back to regexp.Regexp.MatchString.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteMatcher ¶
ByteMatcher matches a byte slice. It either holds a fast-path implementation for the specific regular expression, or the original regexp.Regexp.
func NewByteMatcher ¶
func NewByteMatcher(expr string) (ByteMatcher, error)
NewByteMatcher compiles the regular expression and returns a ByteMatcher that uses the fastest possible comparison for the given pattern shape.
func NewByteMatcherFromRegexp ¶
func NewByteMatcherFromRegexp(re *regexp.Regexp) ByteMatcher
NewByteMatcherFromRegexp analyses the compiled regex and selects the best strategy.
type StringMatcher ¶
StringMatcher matches a string. It either holds a fast-path implementation for the specific regular expression, or the original regexp.Regexp.
func Compile ¶
func Compile(expr string) (StringMatcher, error)
Compile is an alias for NewStringMatcher.
func MustCompile ¶
func MustCompile(expr string) StringMatcher
MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialisation of global variables holding compiled matchers.
func NewStringMatcher ¶
func NewStringMatcher(expr string) (StringMatcher, error)
NewStringMatcher compiles the regular expression and returns a StringMatcher that uses the fastest possible comparison for the given pattern shape.
func NewStringMatcherFromRegexp ¶
func NewStringMatcherFromRegexp(re *regexp.Regexp) StringMatcher
NewStringMatcherFromRegexp analyses the compiled regex and selects the best strategy.