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: +
, -
, *
, /
, ^
, %
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+)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.