Extend expression parser with support for regular expressions #2706
Replies: 3 comments
-
The expression parser does not support regular expressions, therefore it throws a syntax error "Value expected (char 8)". If you need support for regexp you could create a function for it and use that: math.import({
regexp: math.typed({
'string': function (pattern) {
return new RegExp(pattern);
},
'string, string': function (pattern, flags) {
return new RegExp(patter, flags);
}
})
});
// create a regexp testing whether a string contains only digits
math.eval('r=regexp("^\\\\d+$")', scope);
// use the created regexp
math.eval('r.test("123")', scope); // returns true
math.eval('r.test("a23")', scope); // returns false |
Beta Was this translation helpful? Give feedback.
-
Ok, thanks for you answer. |
Beta Was this translation helpful? Give feedback.
-
There are no short term plans to integrate support for regular expressions. You're the first one with this request. I will change the title of this issue to "Support for RegExp" and mark it as a feature request. |
Beta Was this translation helpful? Give feedback.
-
For the code bellow:
math.eval('typeof(/a regexp/)')
the library throws the following error:
Uncaught SyntaxError: Value expected (char 8)
The following code works just fine:
math.eval('typeof(123)')
=>'number'
math.typeof(/a regexp/)
=>RegExp
Is this an issue?
Beta Was this translation helpful? Give feedback.
All reactions