keep only alphabet characters

You can use String.replaceAll(regex, replacement) with the regex [^A-Za-z]+ like this:

String newstr = "Word#$#$% Word 1234".replaceAll("[^A-Za-z]+", "");
// newstr will become WordWord

Edit: Although OP hasn’t mentioned anything about unicode characters but since @Joey has made a comment and if at all there a requirement to keep unicode characters then \\P{L}+ regex should be used like this:

String newstr = "Word#$#$% Word λ1234ä, ñ, ж".replaceAll("\\P{L}+", "");
// newstr will become WordWordλäñж

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)