Regular expression to match digits and basic math operators

前端 未结 9 1884
孤城傲影
孤城傲影 2020-12-03 05:49

I need a regular expression that will match 0-9, (,),+,-,* and /.

9条回答
  •  醉话见心
    2020-12-03 06:35

    If you need a regex to match an arithmetic expression like this: 3+2-24*2/2-1 you can try this:

    String reg1="([0-9]+[\\+\\-\\*\\/]{1}[0-9]+)+([\\+\\-\\*\\/]{1}[0-9]+)*";
    

    You can add the bracket where do you want if you'll edit this regex.

提交回复
热议问题