Make the replace function of the eval language accepting regex

This commit is contained in:
Eric Coissac committed 2025-04-10 15:17:15 +02:00
1 parent c2f38e737b
commit a57cfda675
4 files changed
+75 -6

No files matched your search

+4 -1
View File
@@ -3,6 +3,7 @@ package obiseq
import (
"fmt"
"reflect"
"regexp"
"strings"
log "github.com/sirupsen/logrus"
@@ -204,6 +205,8 @@ var OBILang = gval.NewLanguage(
return scomp, nil
}),
gval.Function("replace", func(args ...interface{}) (interface{}, error) {
return strings.ReplaceAll(args[0].(string), args[1].(string), args[2].(string)), nil
pattern := regexp.MustCompile(args[1].(string))
results := pattern.ReplaceAllString(args[0].(string), args[2].(string))
return results, nil
}),
)