Problem using str_replace_all

Dear All,
I am trying to replace consequtive letters with a single one:
My code is:

mutate(word = str_replace_all(word, "(.)\1+", "\1"))

Everything seems to work but I checked and word "well" has become "wel".

How can I modify my regex?

I tried

mutate(word = str_replace_all(word, "(.)\2+", "\1"))

but it throws mistake

Please help

Can you share sample of the input and desired output?

Yes I want to replace input
with output
For now I get:

So is it fair to say that you don't want to replace consecutive letters, but want to reduce triple consecutives to double consecutives?

Yes correct but still can be more than tripples.

I still want to return well

Not sure if this is going to scale well, do you have more examples?

word <- "Wellll"

str_replace_all(word, "(.)\\1{2,}", "\\1\\1")
#> [1] "Well"

Created on 2020-04-21 by the reprex package (v0.3.0.9001)

Thank you should be fine

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.