Java删除所有感叹号

Java删除所有感叹号,java,regex,string,replace,Java,Regex,String,Replace,我有一个简单的问题,我需要删除Java中HTML字符串中的所有感叹号。 我试过了 testo = testo.replaceAll("\\\\!", "! <br>"); testo=testo.replaceAll(“\\\\!”,“!”); 及 regex=“\\s*\\b!\\b\\s*”; testo=testo.replaceFirst(regex,“”); 及 testo=testo.replaceAll(“\\\\!”,“!”); 但是不起作用。有人能帮我吗?

我有一个简单的问题,我需要删除Java中HTML字符串中的所有感叹号。 我试过了

testo = testo.replaceAll("\\\\!", "! <br>");
testo=testo.replaceAll(“\\\\!”,“!
”);

regex=“\\s*\\b!\\b\\s*”;
testo=testo.replaceFirst(regex,“
”);

testo=testo.replaceAll(“\\\\!”,“!
”);
但是不起作用。有人能帮我吗?
另一个小问题,我需要用一条特征线替换1、2或3个感叹号
谢谢大家

为什么需要正则表达式来完成此操作?您只需执行
String#替换

testo = testo.replace("!", "! <br>");
testo=testo.replace(“!”,“!
”);
但是,要删除多个感叹号,请使用:

testo = testo.replaceAll("!+", "! <br>");
testo=testo.replaceAll(“!+”,“!
”);
为什么需要正则表达式来完成此操作?您只需执行
String#替换

testo = testo.replace("!", "! <br>");
testo=testo.replace(“!”,“!
”);
但是,要删除多个感叹号,请使用:

testo = testo.replaceAll("!+", "! <br>");
testo=testo.replaceAll(“!+”,“!
”);
您不必逃避感叹号:

testo = testo.replaceAll("!{1,3}", "! <br>");
testo=testo.replaceAll(“!{1,3}”,“!
”;
应该这样做


{1,3}
表示连续出现1到3次。

您不必转义感叹号:

testo = testo.replaceAll("!{1,3}", "! <br>");
testo=testo.replaceAll(“!{1,3}”,“!
”;
应该这样做


{1,3}
表示连续出现1到3次。

您要转义什么
用于?:>无论如何,考虑<代码> RePASTALL(“!+”,“!”BR>)<代码>谢谢!成功了!不知道这个越狱
在正则表达式语法中并不特殊(本身)<代码>+
表示“匹配一次或多次”。如果您只想匹配最多3次(我之前的评论将匹配一行中的“!”:例如1、4..或5000次),请参阅Jerry的答案。您要转义什么
用于?:>无论如何,考虑<代码> RePASTALL(“!+”,“!”BR>)<代码>谢谢!成功了!不知道这个越狱
在正则表达式语法中并不特殊(本身)<代码>+
表示“匹配一次或多次”。如果您只想匹配最多3次(我之前的评论将与一行中的“!”匹配的次数相同:例如1、4..或5000次)。“我需要用一条特征线替换1、2或3个感叹号”“我需要用一条特征线替换1、2或3个感叹号”