1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00
birdwatcher/bird/utils.go

21 lines
370 B
Go
Raw Permalink Normal View History

2017-07-14 15:42:45 +02:00
package bird
import (
"regexp"
)
/*
Template Replace:
See https://golang.org/pkg/regexp/#Regexp.Expand
for a template reference.
*/
func TemplateExpand(expr, template, input string) string {
reg := regexp.MustCompile(expr)
match := reg.FindStringSubmatchIndex(input)
dst := []byte{}
res := reg.ExpandString(dst, template, input, match)
return string(res)
}