Regular expression to match digits and basic math operators

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

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

9条回答
  •  一整个雨季
    2020-12-03 06:35

    This works for mathematical expression with 4 decimal places:

    ^([-+]? ?(\d+(\.\d{0,4})?|\(\g<1>\))( ?[-+*\/] ?\g<1>)?)$
    

    It's inspired in base of @ndnenkov answer.

    I hope that can be useful for someone.

提交回复
热议问题