String foo = "a3#4#b"; String afterPunctutationRemoval = foo.replaceAll("[,.;:?!'-_\"/()\\{}]", ""); System.out.println(afterPunctutationRemoval);
he gives me "a ## b", can someone explain to me why?
Shouldn't the string be returned as it is?
Your character class contains a range '.. _, which also matches numbers.
'
_
Put -at the beginning or end of the character class:
-
foo.replaceAll("[,.;:?!'_\"/()\\{}-]", "")
or remove it:
foo.replaceAll("[,.;:?!'\\-_\"/()\\{}]", "");
'-_matches each character between 'and _.
'-_
, - - \\-.
\\-
, \\{ , {, ? , - \\\\{
\\{
{
\\\\{