tpl: Add limit support to replaceRE

Go stdlib doesn't contain a limited replace in the regexp package, but
we can accomplish the same thing with ReplaceAllStringFunc.

Fixes #7586
This commit is contained in:
Cameron Moore
2020-08-28 09:29:26 -05:00
committed by Bjørn Erik Pedersen
parent 047af7cfe5
commit cdfd1c99ba
3 changed files with 49 additions and 14 deletions

View File

@@ -99,7 +99,16 @@ func init() {
ns.AddMethodMapping(ctx.ReplaceRE,
[]string{"replaceRE"},
[][2]string{},
[][2]string{
{
`{{ replaceRE "a+b" "X" "aabbaabbab" }}`,
`XbXbX`,
},
{
`{{ replaceRE "a+b" "X" "aabbaabbab" 1 }}`,
`Xbaabbab`,
},
},
)
ns.AddMethodMapping(ctx.SliceString,