[英]Regex match equation strings
Hi I'm trying to make a regex for matching simple math equations strings such as: 嗨,我正在尝试制作一个正则表达式来匹配简单的数学方程式字符串,例如:
565+9^4/22*5
I want to only allow to following arthemithic operators: +
, -
, *
, /
, ^
, %
我只想允许以下artemithic运算符: +
, -
, *
, /
, ^
, %
and the equation has no set length, it can be as long as it the user wants it to be. 并且方程式没有设置长度,可以是用户希望的长度。
I tried using something like: 我尝试使用类似:
\\d+[+\\-*\\/^%]\\d+
That matches for example: 例如匹配:
2*3+3+3
But it doesn't match: 但这不匹配:
2*3+3
You need to repeat matches for a "number and operator" combination. 您需要为“数字和运算符”组合重复匹配项。 So you are looking for: 因此,您正在寻找:
(\d+[+\-*\/^%])*(\d+)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.