Reputation: 513
I want to find all the letters that are repeated more than three times in the beginning of a word, like
wwwhat
then only keeping one repeated letter. Then add a (repeat)
at the end.
So wwwhat
will become what (repeat beginning)
.
Also I want to find letters that are repeated more than three times inside a word, like
whaaat
and let it become what (repeat inside)
.
So far I have tried
(\S+)(\w)\1{2,}(\S+)
for repetition inside a word but it doesn't work.
There are no multiple repetitions like wwwhaaaat
.
Thank you very much!
Upvotes: 2
Views: 178
Reputation: 26074
You can use the following pattern:
([a-zA-Z])\1{2,}(.*$)
([a-zA-Z])
Match and capture a lower or upper case letter. \1{2,}
Match same letter matched by the first capture group, 2 or more times.(.*$)
Match and capture the rest of the string.Replacing with:
\1\2 (repeat)
Check the regex live here.
Upvotes: 3