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("+", " +");