String.split() at a meta character +
I had similar problem with regex = "?"
. It happens for all special characters that have some meaning in a regex. So you need to have "\\"
as a prefix to your regex.
rightside = rightside.replaceAll("\\+", " +");
replaceAll
accepts a regular expression as its first argument.
+
is a special character which denotes a quantifier meaning one or more occurrences. Therefore it should be escaped to specify the literal character +
:
rightside = rightside.replaceAll("\\+", " +");
(Strings are immutable so it is necessary to assign the variable to the result of replaceAll
);
An alternative to this is to use a character class which removes the metacharacter status:
rightside = rightside.replaceAll("[+]", " +");
The simplest solution though would be to use the replace
method which uses non-regex String
literals:
rightside = rightside.replace("+", " +");