yatwiki/regex.go

16 lines
389 B
Go
Raw Normal View History

2017-07-09 00:13:16 +00:00
package yatwiki3
import (
"regexp"
)
func PregReplaceCallback(pattern *regexp.Regexp, cb func([]string) string, content string) string {
// FIXME avoid double-matching
// Submit to upstream https://github.com/golang/go/issues/5690
return pattern.ReplaceAllStringFunc(content, func(fullmatch string) string {
parts := pattern.FindStringSubmatch(fullmatch)
return cb(parts)
})
}