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,}.*"
しかし、hellooooooooo を hellooo などに置き換えるにはどうすればよいでしょうか。
次のいずれかで、必要な結果が生成されます。
s = s.replaceAll("([a-z])\\1+", "$1$1"); s = s.replaceAll("(([a-z])\\2)\\2*", "$1");