I get user input including non-ASCII characters and non-printable characters, such as
\\xc2d
\\xa0
\\xe7
\\xc3\\ufffdd
\\xc3\\ufffdd
\\xc2\\xa0
\\xc3\\xa7
I know it's maybe late but for future reference:
String clean = str.replaceAll("\\P{Print}", "");
Removes all non printable characters, but that includes \n (line feed), \t(tab) and \r(carriage return), and sometimes you want to keep those characters.
For that problem use inverted logic:
String clean = str.replaceAll("[^\\n\\r\\t\\p{Print}]", "");