I need to look up a string if it has a + character, like this:
teste = teste.replaceAll("+", "e");
but I get this error:
java.util.regex.PatternsSyntaxException: Dangling meta character '+'
I need to look up a string if it has a + character, like this:
teste = teste.replaceAll("+", "e");
but I get this error:
java.util.regex.PatternsSyntaxException: Dangling meta character '+'
The +
character is reserved in regular expressions, so it is necessary to escape it, however in Java
the \
character is used to escape expressions within String
, so there is a need to use it twice to ensure literal use. Replacing in your expression would look like this:
teste = teste.replaceAll("\+", "e");
The% w of% after a string of characters means "one or more occurrences", for example: +
which means "one or more occurrences of a number (from zero to nine)."