我写了一个regex
\blates(t|)?\b在句子"/man/service/man-aaaaaa-lllll-latest/zzzn2-iii-ooo-x00_00-gg".中搜索“最新”一词
我在Rego操场上测试“Rego”中的一个规则,当一个句子中有一个单词“最新”时,我想得到一个布尔输出作为“true”。
Rego游乐场链接:https://play.openpolicyagent.org/p/e3vDQyYKlc
Rego输入
{
"message": "/man/service/man-aaaaaa-lllll-latest/zzzn2-iii-ooo-x00_00-gg"
}Rego规则:
package play
default hello = false
hello {
m := input.message
regex.match("\blates(t|)?\b", m)
}当前产出:
{
"hello": false
}每当Regex与单词“最新”匹配时,预期的输出:
{
"hello": true
}如果我必须使用任何其他的Regex条件来达到预期的结果,请建议https://www.openpolicyagent.org/docs/latest/policy-reference/#regex
发布于 2022-04-18 09:33:58
您可以使用
regex.match("\\blatest?\\b", m)或
regex.match(".*\\blatest?\\b.*", m)请注意,(t|)?是一个与t或空字符串匹配的捕获组,基本上等于匹配可选t char的t?模式(不需要捕获t)。
https://stackoverflow.com/questions/71909662
复制相似问题