Skip to content

Strings and numbers#

CEL inspects and compares strings and numbers with built-in functions and operators. Examples on this page use this message:

{
    "name": "Alice",
    "roles": ["admin", "editor", "viewer"],
    "age": 30,
    "email": "alice@example.com",
    "created": timestamp("2025-12-14T00:00:00Z"),
    "email_verified": timestamp("2025-12-14T18:30:00Z")
}

String functions#

endsWith() checks if a string ends with a given suffix.

user.email.endsWith("@example.com")
// result: true (bool)
user.email.endsWith("@gmail.com")
// result: false (bool)

contains() checks for a substring anywhere in the string.

user.email.contains("@")
// result: true (bool)

startsWith() checks the beginning of a string.

user.name.startsWith("Al")
// result: true (bool)

matches() tests a RE2 regular expression.

user.email.matches("^[a-z]+@[a-z]+\\.[a-z]+$")
// result: true (bool)

size() returns the number of Unicode code points.

size(user.name)
// result: 5 (int)
size(user.email)
// result: 17 (int)

Use size() to check that a field is non-empty.

size(user.name) > 0 && size(user.email) > 0
// result: true (bool)

String concatenation#

+ joins strings together.

user.name + " <" + user.email + ">"
// result: "Alice <alice@example.com>" (string)

Numeric comparisons#

Standard comparison operators work on numbers.

user.age >= 18
// result: true (bool)
user.age > 30
// result: false (bool)
user.age == 30
// result: true (bool)

Check a range by combining two comparisons.

user.age >= 13 && user.age < 65
// result: true (bool)

Combining checks#

String functions and numeric comparisons combine naturally with && and ||.

user.age >= 18 && user.email.endsWith("@example.com")
// result: true (bool)
user.name.startsWith("Al") || user.age > 65
// result: true (bool)

See also#