Writing Expressions
The program includes a very powerful expression processor for validation and filtering. Here are some of the features and syntax used by that processor.
Supported Literals
-
strings - single and double quotes (e.g. “hello”, ‘hello’)
-
numbers - e.g. 103, 2.5, .5
-
dates - “2020-10-09” (yyyy-mm-dd)
Comparison Operators
| operator | meaning |
|---|---|
| == | equal |
| != | not equal |
| < | less than |
| > | greater than |
| <= | less than or equal to |
| >= | greater than or equal to |
Logical Operators
- not or !
- and or &&
- or or ||
String Operators
| operator | meaning |
|---|---|
+ | concatenation |
matches | regex match |
contains | string contains |
startsWith | has prefix |
endsWith | has suffix |
Membership Operators
| operator | meaning |
|---|---|
in | contain |
not in | does not contain |
Example:
$GROUP in ["human_resources", "marketing"]
Numeric Operators
| operator | meaning |
|---|---|
.. | inclusive range (e.g. 1..3 == [1, 2, 3]) |
Example:
$AGE in 18..45
Ternary Operators
- $FOO ? ‘yes’ : ‘no’
Example:
$AGE > 30 ? "mature" : "immature"
Short-Circuit Evaluation
The expression processor uses short-circuit evaluation, meaning that it will stop evaluating an expression as soon as the result is known.
For example, in the expression:
$QTY != nil && $QTY > 10
if $QTY is nil (meaning there was no value supplied in that cell), the second part of the expression
(where we are comparing $QTY with a number) will not be evaluated, preventing an improper comparison
(nil > 10) which would have resulted in an error.