Make the replace function of the eval language accepting regex

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

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
}),
)