Regex to replace consecutive characters in a string in Java [duplicate]


This question already has an answer here:



What is the meaning of this regex given in this expression?



s = s.replaceAll("(.)\1", "");



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



Check this out: https://www.regular-expressions.info/backref.html



It appears from the title of your post and the information above that this will replace repeated characters with an empty String. The 1 in the regex looks for repeated characters and the first group in the regex (.) looks for any character.

Popular posts from this blog

大跃进

马相伯