So I have a string I would like to parse and I can not get my regular expression to work. I am using https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp as my regular expression guide.
I would like my regular expression to match on any of the following symbols.
+ - * % /
My code as follows. Input String: D[1]+D[0]. Should print true…but prints false.
String tmp = "D[1]+D[0]";
if(tmp.matches("[\\+\\-\\*\\/\\%]"))
System.out.println("true");
else
System.out.println("false");
Any ideas?
This is because
matcheswants the entire string to be matched, not just any part of it.You do not need to escape characters inside square brackets.