What you will do
You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.
How it works
matches() tests text against an RE2-style regular expression supplied by the CEL implementation. ^ anchors the start, $ anchors the end, [A-Z]{2} requires two uppercase ASCII letters, and [0-9]{4} requires four digits. The hyphen between them is literal.
Read the prepared example
The CEL + JSON rule is:
code.matches('^[A-Z]{2}-[0-9]{4}$')Its input is:
{
"code": "SK-2026"
}The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.
Evaluation step by step
SKsatisfies the first character class and count.-occurs in the required position.2026satisfies the four-digit requirement, so the result istrue.
Your task
- Run the valid code.
- Change it to
sk-2026. - Change it to
SK-26, then explain which part of the pattern rejects each value.
Expected observation: Both modified values return false: one violates case, the other violates digit count.
Common mistake
A regular expression that is hard to explain is hard to maintain. Prefer named string checks for simple prefix, suffix, or fragment rules.
Show the explanation
The pattern could match a suitable fragment inside a longer string rather than the complete value.
Knowledge check
What would happen if the start and end anchors were removed?
Key takeaway
Use matches() for genuine formats, anchor full-value rules, and explain every pattern component.
Sources
CEL-DEV— official CEL overview.CEL-LANG— official CEL language definition.CEL-GO-BIND— official documentation for the optionalcel.bind()extension used by the self-contained tab.