I am developing an expression evaluator, and I have the following code to check that I do not know about the following combination of characters
for example:
* - a multiplication followed by two signs of subtraction
* / a multiplication followed by a division
* + a multiplication followed by a sum
this is the code that works correctly
private static Boolean EvaluaExprMat(String expr)
{
for(int pos = 0; pos < expr.Length - 1; pos++)
{
char car1 = expr[pos];
char car2 = expr[pos + 1];
if (car1 == '+' || car1 == '-' || car1 == '*' || car1 == '/' || car1 == '^')
if (car2 == '+' || car2 == '*' || car2 == '/' || car2 == '^')
return true;
}
for (int pos = 0; pos < expr.Length - 2; pos++)
{
char car1 = expr[pos];
char car2 = expr[pos + 1];
char car3 = expr[pos + 2];
if (car1 == '+' || car1 == '-' || car1 == '*' || car1 == '/' || car1 == '^')
if (car2 == '+' || car2 == '-' || car2 == '*' || car2 == '/' || car2 == '^')
if (car3 == '+' || car3 == '-' || car3 == '*' || car3 == '/' || car3 == '^')
return true;
}
How could I run these evaluations using regular expressions? can someone help me a bit with this issue, I want to reduce the code using that kind of tool. Thanks