CH04-L02 · applied

Prefixes, suffixes, and contained text

Check three concrete properties of one string.

General CELRuns hereDocumented
What will I learn?

You can choose startsWith(), endsWith(), or contains() to match the exact rule.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

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

startsWith(), endsWith(), and contains() answer different questions. The example demands a path under docs/, a Markdown suffix, and the exact fragment /guide. These checks are case-sensitive and do not normalize path separators.

Read the prepared example

The CEL + JSON rule is:

path.startsWith('docs/') && path.endsWith('.md') && path.contains('/guide')

Its input is:

{
  "path": "docs/cel/guide.md"
}

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

  1. The prefix check is true.
  2. The suffix and contained-fragment checks are also true.
  3. All three booleans joined by && return true.

Your task

  1. Run the example.
  2. Change .md to .txt and identify the failed check.
  3. Change guide to Guide and observe case sensitivity.

Expected observation: Either change makes the whole expression false for a specific, explainable reason.

Common mistake

Do not replace a clear prefix or suffix check with a regular expression unless the rule genuinely needs a pattern.

Show the explanation

No. It only proves that the fragment occurs somewhere in the string.

Knowledge check

Does contains("docs") prove that a path starts in the docs/ directory?

Key takeaway

Choose the string method that states the exact question; simple methods are usually easier to review.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.