Question Details

No question body available.

Tags

regex google-sheets google-sheets-formula re2

Answers (3)

February 15, 2026 Score: 2 Rep: 22,380 Quality: Medium Completeness: 80%

Split the string into characters, go through them individually, and check each against the previous character while building the result string with reduce(), like this:

=reduce(, regexextract(A2, rept("(.)", len(A2))), lambda(a, c,
  a & left(c, right(a)  c)
))

If you need to work with multi-byte characters, separate the string into characters with split(), remove duplicates with filter(), and combine with join():

=let(
  t, totext(D2),
  s, if(isnumber(D2), "→", 0 & t),
  v, arrayformula(totext(split(regexreplace(t, "(.)", "$1" & s), s,))),
  join(, ifna(filter(hstack(v,), hstack(v,)  hstack(,v))))
)

See reduce(), regexextract(), regexreplace(), let(), split(), join(), filter() and hstack().

February 16, 2026 Score: 1 Rep: 14,105 Quality: Low Completeness: 70%

This problem can be solved with REDUCE by initializing the accumulator with an empty value, scanning the input string from left to right, and appending the current character to the accumulator only if it's different than the character that follows it.

Assuming the string is in A1, the formula would be:

=REDUCE(, SEQUENCE(LEN(A1)), LAMBDA(acc, i, IF( MID(A1, i, 1) = MID(A1, i+1, 1), acc, acc & MID(A1, i, 1) ) ))
February 16, 2026 Score: 0 Rep: 730 Quality: Low Completeness: 70%

If you want to safely handle most Unicode characters, you should use the insert/split approach. Insert an uncommon symbol (♦) to the right of every character and then split on that character. Comparing elements of that array with its neighbor will pick up on duplicates that MID/LEFT/RIGHT tend to miss. Most notibly, it helps with emoji and astral plane characters.

=INDEX(LET(
    str, D2,
  chars, SPLIT(REGEXREPLACE(str & "","(.)","$1♦"),"♦"),
 JOIN(, IF({"",chars}={chars,""},,{chars,""}))))

Sample sheet: Testing for consecutive duplicates

enter image description here