Support strings as regular expressions

pull/925/head
Zef Hemel 2024-07-07 12:10:18 +02:00
parent a0ac6e66f9
commit d6d06abe64
2 changed files with 4 additions and 1 deletions

View File

@ -259,6 +259,9 @@ function evalSimpleExpression(type: string, val1: any, val2: any, val3: any) {
return r.test(val1);
}
case "!=~": {
if (typeof val2 === "string") {
val2 = [val2, "i"];
}
if (!Array.isArray(val2)) {
throw new Error(`Invalid regexp: ${val2}`);
}

View File

@ -87,7 +87,7 @@ Simple boolean expression: {{"pete" = "pete" or "hank" = "pete"}}
* `<=` less than or equals, e.g. `age <= 10`
* `>` greater than, 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\//`
* `in` member of a list (e.g. `prop in ["foo", "bar"]`)
* `+` addition (can also concatenate strings), e.g. `10 + 12` or `name + "!!!"`