我有:
String str = txtInput.getText();
String words[] = str.replaceAll("\\p{P}", "").split("\\s+");
Run Code Online (Sandbox Code Playgroud)
...但我也需要它来删除数字。
将您的正则表达式缩小为仅包含非字母字符(和空格,以便您可以拆分)。
String[] words = str.replaceAll("[^A-za-z ]", "").split("\\s+");
Run Code Online (Sandbox Code Playgroud)