rego Regex匹配句子的特定单词
我已经写了一条正则
\blates(t|)?\b
搜索句子中的单词“最新”/man/service/man-aaaaaa-llllll-latest/zzzn2-iii-ooo-x00_00-gg”。
我正在通过Rego Playground测试“ Rego”中的规则,每当句子中有一个单词“最新”时,我都想将布尔输出作为“ True”。
Playground链接: https://play.openpoly.openpolycyagent.orgg/p/p/p/p/p/p/p/pp/e3vdqyyyklc
Reco
{
"message": "/man/service/man-aaaaaa-lllll-latest/zzzn2-iii-ooo-x00_00-gg"
}
grougeo规则:
package play
default hello = false
hello {
m := input.message
regex.match("\blates(t|)?\b", m)
}
当前输出:
{
"hello": false
}
每当REGEX与“最新”一词的匹配时,预期输出:
{
"hello": true
}
如果我使用任何其他正则条件来达到预期结果 https://www.openpolicyagent.org/docs/latest/policy-reference /#REGEX
I've written a regex
\blates(t|)?\b
to search for a word "latest" in a sentence "/man/service/man-aaaaaa-lllll-latest/zzzn2-iii-ooo-x00_00-gg".
I'm testing a rule in 'Rego' through Rego playground, whenever there's a word 'latest' in a sentence, I want to get a boolean output as 'true'.
Rego Playground link: https://play.openpolicyagent.org/p/e3vDQyYKlc
Rego input
{
"message": "/man/service/man-aaaaaa-lllll-latest/zzzn2-iii-ooo-x00_00-gg"
}
Rego rule:
package play
default hello = false
hello {
m := input.message
regex.match("\blates(t|)?\b", m)
}
Current output:
{
"hello": false
}
Expected output whenever Regex has a match for the word 'latest':
{
"hello": true
}
Please suggest if I've to use any other Regex condition to achieve the expected result
https://www.openpolicyagent.org/docs/latest/policy-reference/#regex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
或
查看 rego playgoground demo 。
请注意,
(t |)?
是匹配t
或空字符串的捕获组,并且基本上等于t?
模式(那里无需捕获与可选t
char匹配的t
)。You can use
or
See the Rego playground demo.
Note that
(t|)?
is a capturing group that matches at
or empty string, and is basically equal tot?
pattern (there is no need to capture thet
) that matches an optionalt
char.