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.
假设我有一个像这样的字符串:
String s = "hellllooooo howwwwwww areeeeeee youuuuuuu";
我想丢弃重复的字母并想得到:
"helloo howw aree youu"
我已经使用 :: 完成了匹配
matches(".*([a-z])\\1{3,}.*"
但是我怎样才能将 helloooooooo 替换为 helloo 和其他?
以下任何一项都会产生您想要的结果:
s = s.replaceAll("([a-z])\\1+", "$1$1"); s = s.replaceAll("(([a-z])\\2)\\2*", "$1");