Commit f4971a0d authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

zre

parent 5a331752
package zre
import (
"regexp"
)
var cache map[string]*regexp.Regexp
func init() {
cache = make(map[string]*regexp.Regexp)
}
func New(s string) *regexp.Regexp {
if r, ok := cache[s]; ok {
return r
}
cache[s] = regexp.MustCompile(s)
return cache[s]
}
func Replace(expr string, s, rep string) string {
return New(expr).ReplaceAllString(s, rep)
}
func Match(expr, s string) bool {
return New(expr).MatchString(s)
}
func FindAll(expr, s string, n int) []string {
return New(expr).FindAllString(s, n)
}
func Find(expr, s string) string {
return New(expr).FindString(s)
}
func FindSubmatch(expr, s string) []string {
return New(expr).FindStringSubmatch(s)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment