如何仅删除标点符号但保留重音字母?

use*_*920 2 java string

我试图仅从文本数据中删除标点符号,但保留重音字母。我不想用英语等效字母替换带重音的字母。我不知道如何调整现有代码以允许更高的 ASCII 字符。

\n\n
    while (input.hasNext()){\n        String phrase = input.nextLine();\n        String[] words = phrase.split(" ");\n        for(String word: words){\n              String strippedInput = word.replaceAll("[^0-9a-zA-Z\\\\s]", ""); \n        }\n     }\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果原始输入是:\nO sal, ou os\xc3\xb3dio, tamb\xc3\xa9m \xc3\xa9 contraindicado em pacientes hipotensos?

\n\n

预期输出应为: \nO sal ou os\xc3\xb3dio tamb\xc3\xa9m \xc3\xa9 contraindicado em pacientes hipotensos

\n\n

有任何想法吗?谢谢!

\n

use*_*740 5

考虑使用Unicode 类别,因为“AZ”非常以英语为中心,甚至无法处理所发现的重音。

例如,以下内容将替换所有内容,包括标点符号,但“任何字母、任何语言”( ) 或“空格” ( )除外。如果需要保留数字,请将它们添加回作为附加排除项。\p{L}\s

replaceAll("[^\\p{L}\\s]", "")
Run Code Online (Sandbox Code Playgroud)

这是一个 ideone 演示