Skip to main content

Rules

Rules Syntax

A rule is a string that represents a boolean expression. It should be in the format <variable> <operator> <value>. Additionally, rules can be combined in the following format <rule> <logical expression> <rule>. Quotes inside the rules need to be escaped appropriately.

The following operators are supported:

Logical Expressions

OperatorMeaningExample
!, notboolean "not"not(country = "US")
or, \|, \|\|boolean "or"country = "US" or age < 50
and, &, &&boolean "and"age > 20 and age < 50

Relational Expressions

OperatorMeaningExample
=, ==, is, eqequal tocountry = "US"
~=, =~loose equal toage ~= "20"
<, ltless thanage < 50
>, gtgreater thanage > 20
<=less than or equalage <= 50
>=greater than or equalage >= 20
inpresent in list of itemscountry in ["US", "FR"]
inpresent in range of valuesage in 20 to 50

Quantifiers

OperatorMeaningExample
oneOfgroup of boolean "or"soneOf(country = "US", age < 50)
allOfgroup of boolean "and"sallOf(age > 20, age < 50)
existsfirst-order "or" operatorexists(c:countries, c == "US")
forAllfirst-order "and" operatorforAll(p:purchases, p > 50)

String Expressions

OperatorMeaningExample
containsstring containsuser-agent contains "Chrome"
startsWithstring startsWithuser-agent startsWith "Chrome"
endsWithstring endsWithuser-agent endsWith "81"
matchesstring matches regexuser-agent matches /^(Chrome\|Firefox)$/
containsWordstring contains wordcategory containsWord "summer"
info

The containsWord operator ensures to match "whole words" only taking into account word boundaries.

A word boundary is any character that is not a-z, A-Z, 0-9, _ including or excluding diacritics.

Array Expressions

OperatorMeaningExample
containsAllarray contains all elementsids containsAll [1, 2, 3]
containsAnyarray contains any elementids containsAny [1, 2, 3]
containsAllWordsarray contains all wordscategories containsAllWords ["Summer", "Sale"]
containsAnyWordarray contains any wordcategories containsAnyWord ["Summer", "Sale"]
info

The containsAllWords and containsAnyWord operators ensure to match "whole words" only taking into account word boundaries.

A word boundary is any character that is not a-z, A-Z, 0-9, _ including or excluding diacritics.

Geo Expressions

OperatorMeaningExample
near byvalue near coordinateuserCoordinates near [41.176296, -8.596050] by 30 km

Date Expressions

OperatorMeaningExample
aftertimestamp is after x dayslastPurchase after 7 days ago
beforetimestamp is before x dayslastPurchase before 3 days ago
betweentimestamp is between x and y dayslastPurchase between 3 and 7 days ago

Built-In Functions

FunctionMeaningExample
isDefinedreturns true if a variable is definedisDefined(country)
normalizereturns the string in lowercase without combining diacriticsnormalize(category)
toStringattempts to convert a value to a stringtoString(status)
toNumberattempts to convert a value to a numbertoNumber(productId)
toBooleanattempts to convert a value to a booleantoBoolean(promotion)
mapreturns a new list with the elements updated based on the expression providedmap(x:products, x["id"])