2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 00:13:16 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|