如何检查验证特定表达式在数学上是正确的(通过正则表达式) [英] how to check validate particular expression is mathematically correct(via regex expression)

查看:102
本文介绍了如何检查验证特定表达式在数学上是正确的(通过正则表达式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

然而,公式很快变得更难,我不知道如何解决以下并发症:

>我需要测试四个简单数学运算符之一(+ - * /)每个代码之间,但不是在最后一个代码之后。

>可以添加任意数量的代码。

>封闭括号可以(X + Y)/ 2

>不匹配的括号不合适。

example-1)(basecomponent + 5)-4 + 5(正确)

2)(8 + 6)( - ((不正确)

3)b + D-6 + 7-(G + 7)(正确)

4)FLR01 + FLR02 + FLR03 + FMD0 + FMR05 +(LS400 + LT400)* LC430 /(EL41 + EL414R)(正确)

5)FLR01 + FLR02FMD0 + - (错误)

However, the formulas quickly got harder and I don’t know how to get around the following complications:
>I need to test for one of the four simple math operators (+-*/) between each code, but not after the last one.
>There can be any number of codes being added together.
>Enclosed parenthesis are okay (X+Y)/2
>Mismatched parenthesis are not okay.
example-1)(basecomponent+5)-4+5 (correct)
2) (8+6)(-( (not correct)
3) b+D-6+7-(G+7)(correct)
4)FLR01+FLR02+FLR03+FMD0+FMR05+(LS400+LT400)*LC430/(EL41+EL414R)(correct)
5)FLR01+FLR02FMD0+-(wrong)

推荐答案

最难的部分是匹配平衡的括号。幸运的是,您可以在网上找到示例,例如,参见使用.NET正则表达式匹配平衡构造 [< a href =http://weblogs.asp.net/whaggard/377025target =_ blanktitle =New Window> ^ ]。
The hardest part is matching the balanced parentheses. Luckily you may find examples on the web, see, for instance, "Matching Balanced Constructs with .NET Regular Expressions"[^].


这篇关于如何检查验证特定表达式在数学上是正确的(通过正则表达式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆