package main
import (
"fmt"
"os"
"strings"
"github.com/oleksandr/conditions"
)
func main() {
s := "[test] =~ /^1`\\d+/"
// Parse the condition language and get expression
p := conditions.NewParser(strings.NewReader(s))
expr, err := p.Parse()
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
test_data := map[string]interface{}{
"test": "1`1499095372",
"2": "1",
}
r, err := conditions.Evaluate(expr, test_data)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println("result:", r)
}
输出:
<input>:1:14: literal not terminated
如何在s
包解析的正则表达式文字conditions
中避免此错误?