I’ve got a text. I want to find out if a certain part of that text is repeated three or more times and replace that by only two repetitions.
For example, in the HTML code I’m looking at, there are 3 or more <br /> in a row and I want to change that to just 2 <br /> in a row.
How can I do that?
Edit: As noted by Tim below, my original answer was altogether incorrect.
The correct regex for replacement would look like:
It means: match any character once, then the same character (
\1) at least twice more ({2,}), and replace the entire matched set with the first character, but only 2 times.However, it might be that the above answers are probably closer to what you want.
For posterity, my original, incorrect regex looked like:
/(.){3,}/ig