I want to get from a string only the character: +,-,/,x
But this says - is a redundant character range.
String operacoes=texto.replaceAll("[^+?-?/?x]+"," ");
How can i make this work?
I want to get from a string only the character: +,-,/,x
But this says - is a redundant character range.
String operacoes=texto.replaceAll("[^+?-?/?x]+"," ");
How can i make this work?
Just add \\ before - character. Because - character used in regex in various ways like
[A-Z] [0- 9] etc. So to identify - you need to put \\ in java because single \ doesn't support in string in java.
String texto="3 + 4 - 5 + 4";
String operacoes=texto.replaceAll("[^+?\\-?/?x]+"," ");
System.out.println(""+operacoes);