I’m using regexp to parse a string of a certain syntax.
Pattern.compile("(\\d+)(d)(\\d+)(([\\+\\-\\*\\/])(\\d+))*"); // The regexp pattern
I want this to match strings like:
2d6
4d4+1
2d12*2-1
The problem is, it also matches strings that end on a x-*/ such as:
3d4-
use this regex
(\d+)(d)(\d+)(([-+*/])(\d+))but 2d12x2-1 would not be match, x is not exist in your regex, and you don’t say about it anything, for include
xchange regex to(\d+)(d)([\dx]+)(([\+\-\*\/])(\d+))Edit:
may be you need anchor? set
^and$in your regex