feat: custom-api's replaceAll with regex support

This commit is contained in:
Ralph Ocdol 2025-03-31 22:24:51 +08:00 committed by Svilen Markov
parent b1247e5de6
commit ea7124db52

View File

@ -468,8 +468,16 @@ var customAPITemplateFuncs = func() template.FuncMap {
return strings.TrimSuffix(s, suffix)
},
"trimSpace": strings.TrimSpace,
"replaceAll": func(old, new, s string) string {
return strings.ReplaceAll(s, old, new)
"replaceAll": func(oldOrPattern, new, s string) string {
if s == "" {
return ""
}
regex := getCachedRegexp(oldOrPattern)
if regex == nil {
return strings.ReplaceAll(s, oldOrPattern, new)
}
return regex.ReplaceAllString(s, new)
},
"findMatch": func(pattern, s string) string {
if s == "" {