I have a variable v that possibly appears more than one time consecutively in a string. I want to make it so that all consecutive vs turn into just one v. For example:
String s = "Hello, world!";
String v = "l";
The regex would turn “Hello, world!” into “Helo, world!”
So I want to do something like
s = s.replaceAll(vv+, v)
But obviously that won’t work. Thoughts?
You need to concatenate the two “v” Strings.
Try
s = s.replaceAll(v + v + "+", v)