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> <boolean operator> <rule>
. Quotes inside the rules need to be escaped appropriately.
The following operators are supported:
Boolean operator | Meaning | Example |
---|
=, ==, is | equal to | country = "US" |
<, lt | less than | age < 50 |
>, gt | greater than | age > 20 |
<= | less than or equal | age <= 50 |
>= | greater than or equal | age >= 20 |
in | present in list of items | country in ["US", "FR"] |
inRange | present in range of values | age inRange (20, 50) |
!, not | boolean "not" | !(country = "US") |
|, ||, or | boolean "or" | country = "US" or age < 50 |
&, &&, and | boolean "and" | age > 20 & age < 50 |
contains | string contains | user-agent contains "Chrome" |
startsWith | string startsWith | user-agent startsWith "Chrome" |
endsWith | string endsWith | user-agent endsWith "81" |
containsAny | array contains any elements | ids containsAll [1, 2, 3] |
containsAll | array contains all elements | ids containsAny [1, 2, 3] |
Geo Operator | Meaning | Example |
---|
near by | value near coordinate | userCoordinates near [41.176296, -8.596050] by 30 km |
Date Operator | Meaning | Example |
---|
after | timestamp is after x days | lastPurchase after 7 days ago |
before | timestamp is before x days | lastPurchase before 3 days ago |
between | timestamp is between x and y days | lastPurchase between 3 and 7 days ago |
Function | Meaning | Example |
---|
oneOf | group of boolean "or"s | oneOf(country = "US", age < 50) |
allOf | group of boolean "and"s | andOf(age > 20, age < 50) |
isDefined | returns true if a variable is defined | isDefined(country) |
exists | first-order "or" operator | exists(c:countries, c == "US") |
forAll | first-order "and" operator | forAll(p:purchases, p > 50) |