我有一个简单的问题,我需要从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>");