Skip to main content

Writing Expressions

Basic Syntax

Expressions are written in CEL and look similar to expressions in C, JavaScript, or Python. They can include variables, literals, and operators.

Variables

Variables are used to refer to values. For example, identity might refer to a user object.

Loading…

Supported Variables

You can find the ngrok supported variables here:

Literals

CEL supports several literal types:

  • Boolean: true, false
  • Integer: 42, -7
  • String: "hello", 'world'
  • List: [1, 2, 3]
  • Map: {"key1": "value1", "key2": "value2"}

Operators

CEL provides a rich set of operators for performing arithmetic, comparison, and logical operations:

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, <, <=, >, >=
  • Logical: &&, ||, !

Using Arithmetic

Loading…

Using Comparison and Logical Operators

Loading…

Working with Strings

String Concatenation

To combine strings, use the + operator:

Loading…

String Functions

CEL provides several built-in functions to work with strings, enabling you to perform transformations, query information, or compare strings.

size()

Returns the number of characters in the string:

Loading…

startsWith()

Checks if the string starts with a specified substring:

Loading…

endsWith()

Checks if the string ends with a specified substring:

Loading…

matches()

Determines if the string matches a regular expression pattern:

Loading…

contains()

To check if a string contains another string:

Loading…

Advanced String Manipulation

Regular Expressions

CEL's matches() function allows you to use regular expressions for pattern matching. This can be powerful for validation or extracting parts of strings:

Loading…

Concatenation and Interpolation

While direct string interpolation isn't a feature in CEL, concatenation can be used to dynamically construct strings:

Loading…

Working with Unicode

Strings in CEL are Unicode and can handle a wide range of characters:

Loading…

String Comparison

String comparison in CEL is case-sensitive and uses the standard comparison operators:

Loading…

Working with Lists

A list in CEL is an ordered collection of elements. You can perform various operations on lists, including checking if an item is contained within a list, accessing elements by their index, and iterating over elements.

Creating a List

Loading…

Checking for Membership

To check if a value exists in a list, use the in operator:

Loading…

Accessing Elements

Access elements by their index (0-based):

Loading…

Counting Elements

Returns the number of elements in the list.

Loading…

Iterating Over a List

Use a comprehension to iterate over elements in a list and apply logic:

Loading…

Filtering a List

Filter a list to include only certain elements:

Loading…

Membership in Lists

The in operator is versatile and can be used to check for membership in both lists:

Loading…

Working with Maps

A map in CEL is a collection of key-value pairs. Keys are unique, and each key maps to exactly one value. You can check for the presence of keys, access values by their keys, and iterate over keys or values.

Creating a Map

Loading…

Checking for Key Presence

To check if a key is present in a map, use the in operator:

Loading…

Accessing Values

Access values by their keys:

Loading…

Counting Elements

Returns the number of key-value pairs present in the map.

Loading…

Iterating Over a Map

You can iterate over the keys or values of a map using a comprehension:

Loading…

Checking for a Condition in a Map

Use exists or all macros to check if any or all elements in a collection meet a condition:

Loading…

Membership in Maps

The in operator is versatile and can be used to check for membership in maps:

Loading…

Conditional Expressions

CEL supports ternary conditional expressions, allowing for simple if-then-else logic:

Loading…

Using Macros

Macros provide syntactic sugar for common patterns, like looping through a collection:

Loading…

You can find the custom ngrok macros here: