Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想替换以下字符串:
铬, 互联网浏览器, mozlla, 歌剧
或者
约翰、杰克、吉尔、比尔
和
?, ?, ?, ?
我需要一个可以替换上述字符串的 Java 正则表达式。查找所有单词并用问号替换
像这样的东西:
String output = myString.replaceAll("(chrome|internet|explorer|mozlla|opera)", "?");
[编辑]您正在更快地更改问题,然后我可以回答。
要替换任何单词:
String output = myString.replaceAll("\b(\w+)\b", "?");
\b- 单词中的第一个或最后一个字符 \w- 字母数字 +- 一个或多个重复
\b
\w
+