Support strings as regular expressions
parent
a0ac6e66f9
commit
d6d06abe64
|
@ -259,6 +259,9 @@ function evalSimpleExpression(type: string, val1: any, val2: any, val3: any) {
|
||||||
return r.test(val1);
|
return r.test(val1);
|
||||||
}
|
}
|
||||||
case "!=~": {
|
case "!=~": {
|
||||||
|
if (typeof val2 === "string") {
|
||||||
|
val2 = [val2, "i"];
|
||||||
|
}
|
||||||
if (!Array.isArray(val2)) {
|
if (!Array.isArray(val2)) {
|
||||||
throw new Error(`Invalid regexp: ${val2}`);
|
throw new Error(`Invalid regexp: ${val2}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ Simple boolean expression: {{"pete" = "pete" or "hank" = "pete"}}
|
||||||
* `<=` less than or equals, e.g. `age <= 10`
|
* `<=` less than or equals, e.g. `age <= 10`
|
||||||
* `>` greater than, e.g. `age > 10`
|
* `>` greater than, e.g. `age > 10`
|
||||||
* `>=` greater than or equals, e.g. `age >= 10`
|
* `>=` greater than or equals, e.g. `age >= 10`
|
||||||
* `=~` to match against a regular expression, e.g. `name =~ /^template\//`
|
* `=~` to match against a regular expression, e.g. `name =~ /^template\//` (the operand can either be a regular expression or a string expression that will be turned into a regular expression)
|
||||||
* `!=~` to not match a regular expression, e.g. `name !=~ /^template\//`
|
* `!=~` to not match a regular expression, e.g. `name !=~ /^template\//`
|
||||||
* `in` member of a list (e.g. `prop in ["foo", "bar"]`)
|
* `in` member of a list (e.g. `prop in ["foo", "bar"]`)
|
||||||
* `+` addition (can also concatenate strings), e.g. `10 + 12` or `name + "!!!"`
|
* `+` addition (can also concatenate strings), e.g. `10 + 12` or `name + "!!!"`
|
||||||
|
|
Loading…
Reference in New Issue