gpt4 book ai didi

Java删除所有感叹号

转载 作者:行者123 更新时间:2023-12-01 18:42:51 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com