From 9d1d2bfe16b445b6ea6e0f7fe1e77e74b07c07cd Mon Sep 17 00:00:00 2001 From: Max Boll Date: Wed, 14 Oct 2020 14:45:05 +0200 Subject: [PATCH] dsl replacement function extended with regex support --- v2/pkg/generators/dsl.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v2/pkg/generators/dsl.go b/v2/pkg/generators/dsl.go index 89449c37..f4794bb6 100644 --- a/v2/pkg/generators/dsl.go +++ b/v2/pkg/generators/dsl.go @@ -12,7 +12,7 @@ import ( "net/url" "regexp" "strings" - + "github.com/Knetic/govaluate" ) @@ -39,7 +39,11 @@ func HelperFunctions() (functions map[string]govaluate.ExpressionFunction) { } functions["replace"] = func(args ...interface{}) (interface{}, error) { - return strings.ReplaceAll(args[0].(string), args[1].(string), args[2].(string)), nil + compiled, err := regexp.Compile(args[1].(string)) + if err != nil { + return nil, err + } + return compiled.ReplaceAllString(args[0].(string), args[2].(string)), nil } functions["trim"] = func(args ...interface{}) (interface{}, error) {