template: Add reReplaceAll function (#639)

This allows for using regexp replacement in templates.
This commit is contained in:
James O'Gorman 2017-03-04 12:07:31 +00:00 committed by Brian Brazil
parent 412d33336d
commit 00e3b98614
1 changed files with 5 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
"bytes"
"net/url"
"path/filepath"
"regexp"
"sort"
"strings"
"time"
@ -130,6 +131,10 @@ var DefaultFuncs = FuncMap{
"safeHtml": func(text string) tmplhtml.HTML {
return tmplhtml.HTML(text)
},
"reReplaceAll": func(pattern, repl, text string) string {
re := regexp.MustCompile(pattern)
return re.ReplaceAllString(text, repl)
},
}
// Pair is a key/value string pair.