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
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.