add regexReplace template function

This commit is contained in:
Dirk Heilig
2017-10-19 14:58:11 +02:00
parent 28d92eb659
commit d3e294e1ce
+5
View File
@@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@@ -131,6 +132,10 @@ func TemplateProcessor() *template.Template {
"color": func(color string) string { "color": func(color string) string {
return ansi.ColorCode(color) return ansi.ColorCode(color)
}, },
"regReplace": func(search string, replace string, content string) string {
re := regexp.MustCompile(search)
return re.ReplaceAllString(content, replace)
},
"split": func(sep string, content string) []string { "split": func(sep string, content string) []string {
return strings.Split(content, sep) return strings.Split(content, sep)
}, },