How to convert heyyyy to hey using python regex ?
This is what i got so far
line="heyyy hoooow are you"
word_normalize=compile(r'(\w)\1+')
word_normalize.sub(r'\1\1',line)
which prints hey how are you
i want it to print : hey hoooow are you
i want only the end letters to be shortened not the other parts.
and what if i wanted something like this
hey hoow are you
i.e the end characters don’t repeat and other characters repeat at max 2 times.
Use
\bto force the match to be at the end of words.To get the inner letters to repeat at max two times, add another substitution using
\B, which is the opposite of\b: