modulepackage
0.0.0-20150417035358-2444a542492f
Repository: https://github.com/umisama/go-regexpcache.git
Documentation: pkg.go.dev
# README
umisama/go-regexpcache 
what's this?
This is a cacheable regexp package. If expression is used two times or more, this returns cached regexp.Regexp object in very less time. go-regexpcache has compatible interface with official regexp package.
Here is simple usage:
import "github.com/umisama/go-regexpcache"
// First time, returns regexp is parsed.
match := regexpcache.MustCompile("^[hc]at").MatchString("cat")
println(match)
// After that, returns regexp from cache in less time.
match = regexpcache.MustCompile("^[hc]at").MatchString("cat")
println(match)
You don't have to pollute global variables with go-regexpcache.
before:
var re = regexp.MustCompile("^[hc]at")
func varidation(str string) bool {
// regexp.Regexp object is global for avoid compile time
return re.MatchString(str)
}
after:
func varidation(str string) bool {
// You can write regexp inside function
return regexpcache.MustCompile("^[hc]at").MatchString(str)
}
intallation
go get github.com/umisama/go-regexpcache
document
license
under the MIT License
# Functions
Compile parses a regular expression.
CompilePOSIX parses a regular expression with POSIX ERE syntax.
Match checks whether a textual regular expression matches a byte slice.
Match checks whether a textual regular expression matches the RuneReader.
Match checks whether a textual regular expression matches a string.
MustCompile parses a regular expression and panic if str can not parsed.
MustCompilePOSIX parses a regular expression with POSIX ERE syntax and panic if str can not parsed.