Dominik Adamski Dominik Adamski - 5 months ago 14
Java Question

Java regex aritmetic operators occurence

I have a little problem with regex in Java. I try make regex, which will be match aritmetic operations.
It is my regex:

[\d]*[-+*/^][\d]*([-+*/^][\d]*)*


It should accept string like 34+45*5^7/3-5, but it also accepts strings like 34+-/^34. I don't know what is wrong in this regex.

Sorry for my English.

Answer

Try this regex and let me know if there are any issues :-

([\d]+[\-\+\*/][\d]+)+