SyntaxFix
Write A Post
Hire A Developer
Questions
You could also try this simpler regex:
str = str.replaceAll("\\P{Alnum}", "");