Matching math expression with regular expression?

前端 未结 8 2126
旧时难觅i
旧时难觅i 2020-11-27 18:36

For example, these are valid math expressions:

a * b + c
-a * (b / 1.50)
(apple + (-0.5)) * (boy - 1)

And these are invalid math expression

8条回答
  •  时光说笑
    2020-11-27 19:13

    For parenthesis matching, and implementing other expression validation rules, it is probably easiest to write your own little parser. Regular expressions are no good in this kind of situation.

提交回复
热议问题