This is basically more complicated version of this question.
Replace repeating characters with one with a regex
If there is a character that repeats more than 20 times, then replace with just ten repetition of that character.
That is, I want to replace 'adfajlkjl a sd=============================================== READFadfa' with 'adfajlkjl a sd========== READFadfa'
import re
string1 = 'adfajlkjl a sd=============================================== READFadfa'
re.sub(pattern1, r'\1\1\1\1\1\1\1\1\1\1', string1)
Output:
'adfajlkjl a sd========== READFadfa'
The above is a brute force solution using the answer in the above link. Is there another way not repeating the backreference \1 ten times?
If your choice of programming language is Python, would you please try:
Result: