regex for simple math equation

后端 未结 2 1573
无人共我
无人共我 2020-12-12 02:16

I want to recognize integers or decimals and the four simple operations, broken into tokens I can\'t get the decimal to work, can you please help?

My reg is

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 02:34

    It may works for you:

    expression = "2.7 + 3 * (1 + 2)";
    String expRegString = "\\d+(\\.\\d+)*|\\(\\d+(\\.\\d+)*[\\+\\-\\*\\/]\\d+(\\.\\d+)*\\)";
    

提交回复
热议问题