我有一个简单的问题,我需要从 Java 中的 HTML 字符串中删除所有感叹号。 我尝试过
testo = testo.replaceAll("\\\\!", "! <br>");
和
regex = "\\s*\\b!\\b\\s*";
testo = testo.replaceFirst(regex, "<br>");
和
testo = testo.replaceAll("\\\\!", "! <br>");
但是不起作用。有人能帮我吗? 另一个小问题,我需要用一条断线替换 1、2 或 3 个感叹号 谢谢大家!
最佳答案
为什么需要正则表达式?您只需执行 String#replace
testo = testo.replace("!", "! <br>");
但是要删除多个感叹号,请使用:
testo = testo.replaceAll("!+", "! <br>");
关于Java删除所有感叹号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190353/