Go literal not terminated错误

时间:2017-07-23 09:46:22

标签: regex go literals

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中避免此错误?

0 个答案:

没有答案