Remove all non-“word characters” from a String in Java, leaving accented characters?

Use [^\p{L}\p{Nd}]+ – this matches all (Unicode) characters that are neither letters nor (decimal) digits.

In Java:

String resultString = subjectString.replaceAll("[^\\p{L}\\p{Nd}]+", "");

Edit:

I changed \p{N} to \p{Nd} because the former also matches some number symbols like ΒΌ; the latter doesn’t. See it on regex101.com.

Leave a Comment