How to remove special characters in the string except \"- _\". Now I use:
replaceAll(\"[^\\\\w\\\\s]\", \"\")
it remove all special charact
I suspect that you need to assign the result (in case you're not doing that), because replaceAll() returns a new string, rather than updating the string (String is immutable):
str = str.replaceAll("[^\\w\\s-]", "");
Also note that the regex is quite simple:
No need to escape the dash - in the character class: When used as a literal in a character class, it must be either first or last (otherwise it indicates a range, like a-z etc).
No need to mention the underscore at all, because it is already listed: \w includes the underscore character!