[Question]
  [
Given a non-empty string (or an integer, or a list/array if you prefer) composed exclusively of digits in the range [1-9], your task is to write a function (or a whole program) that applies a "Match-3 type of rule" from left to right and outputs the resulting string, like this :
```
[parameter] "12223" -> [returned value] "13"
```
Meaning, while parsing the string from left to right if you encounter **the same digit repeated 3 or more times successively**, this whole group of digits must "disappear", resulting in the concatenation of the left and right part of the remaining string.  
  
**Each time you deal with a group, you must start again from the left end and reiterate the same process** until the string no longer changes (normally when you finally reach the right end).  
  
If the string becomes empty at the end of the process, you should output an empty string, or the digit `0`, or an empty list/array as you prefer.
---
Test cases :
```
"1" -> "1"
"31122213" -> "33"
"44555554446" -> "6"
"1322232223222311" -> "1311"
"111" -> ""
"7789998877" -> ""
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest solution in bytes wins.
  
[Answer]
# Python 3.8, 67 bytes
```
import re
f=lambda a:(f,str)[a==(b:=re.sub(r"(.)\1\1+","",a,1))](b)
```
[Try it online!](https://tio.run/##ZYxBCoMwEEX3nkJmNaFBGJM2UchJahcJVSpUDWNc9PRpC60U@uCvHu/HR7ots7KRcx6nuHAquS8Gd/dTuPrStzjINbE4e@cwtI77at0CMmAlOuroABJAeklCXDCIHHmcEw4Iiqiua1JQfhCi2KXWxzda6xP8SVKvcB8R/EpjbNM01hoD39v8BA "Python 3.8 (pre-release) – Try It Online")
[Answer]
# [sed](https://www.gnu.org/software/sed/) `-E`, 18 bytes
Port of [Arnauld's JavaScript answer](https://codegolf.stackexchange.com/a/258202/112488).
```
:l
s/(.)\1\1+//
tl
```
[Try it online!](https://tio.run/##K05N0U3PK/3/3yqHq1hfQ08zxjDGUFtfn6sk5/9/Y0NDIyMjQ2MuExNTEDAxMTHjMjQGisGxoSGXubmFpaWlhYW5@b/8gpLM/Lzi/7quAA "sed – Try It Online")
### Explanation
```
$ info '(sed)Programming Commands'
```
```
:l           # Specify the location of label 'l' for branch commands
s/(.)\1\1+// # Erase the first instance of 3 or more consecutive equal characters
tl           # Branch to label only if there has been a succesful 's'ubstitution
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
(Ġ:‡ḢḢǑ⟇f
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIoxKA64oCh4bii4biix5Hin4dmIiwiIiwiJzEzMjIyMzIyMjMyMjIzMTEnIl0=)
Why use fixed point when you can do too much work?
```
(         # Over each character
 Ġ        # Group identical items
  :   Ǒ   # Find the first group where...
   ‡--    # Next two as lambda
    ḢḢ    # Removing the first two items yields a truthy result
       ⟇  # Remove the group at the index
        f # Flatten the result.
```
[Answer]
# JavaScript (ES6), 42 bytes
Supports less digits than the more generic version below.
```
f=s=>s-(s=s.replace(/(.)\1\1+/,''))?f(s):s
```
[Try it online!](https://tio.run/##Zc7RCoIwFAbg@55Czo0bpeNsy2lgvYg3Y21hiBNP9PorQaLshwP/xcfhv9unJTf306MY49WnFFpqz1Qwaqmc/TRY55lgJe@ww7045Dnnl8CInyi5OFIcfDnEGwsMFKKUEhVkazjPhMhAKdhtqNbHJVrrCr5p9SdRvX9@DhFWiUvfYmPqpmnq2hj4WQDpBQ "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 43 bytes
```
f=s=>s==(s=s.replace(/(.)\1\1+/,''))?s:f(s)
```
[Try it online!](https://tio.run/##Zc5BCsIwEAXQvacos2mC2jBJbFIhepFuSk1ECU3piNePFopo/TDwF4/h37tnR/10Gx/7IV18zsGRO5FzjBxVkx9j13smWMVbbHErdmXJ@ZmOgRHPfRooRV/FdGWBgUKUUqKCYgnnhRAFKAWbFdX6MEdrXcM3rf8kqvfPzyHCInHua2yMbZrGWmPgZwHkFw "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 12 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ΔDγ.Δg3@}õ.;
```
[Try it online](https://tio.run/##yy9OTMpM/f//3BSXc5v1zk1JN3aoPbxVz/r/f0NjIyMjODY0BAA) or [verify all test cases](https://tio.run/##yy9OTMpM/W/p43J4ul6R16FVZZX2SgqP2iYpKNlX/j83xeXcZr1zU9KNHWoPb9Wz/l@r8z/aUMfY0NDIyMjQWMfExBQETExMzHQMjYFicGxoqGMIxObmFpaWlhYW5uaxAA).
`.Δ...}` could alternatively be `D...Ïн` and/or `g3@` could alternatively be `7b@` for equal-bytes alternatives:
[Try it online](https://tio.run/##yy9OTMpM/f//3BSXc5tdzJMcDvdf2Ht4q571//@GxkZGRnBsaAgA) or [verify all test cases](https://tio.run/##yy9OTMpM/W/p43J4ul6R16FVZZX2SgqP2iYpKNlX/j83xeXcZhfzJIfD/Rf2Ht6qZ/2/Vud/tKGOsaGhkZGRobGOiYkpCJiYmJjpGBoDxeDY0FDHEIjNzS0sLS0tLMzNYwE).
**Explanation:**
```
Δ             # Loop until the result no longer changes (using the implicit input):
 D            #  Duplicate the current integer
  γ           #  Split the copy into parts of equal adjacent digits
   .Δ   }     #  Pop and find the first that's truthy for (or -1 if none are):
     g        #   Push the length of the group
      3@      #   Check whether this length is >= 3
         õ    #  Push an empty string ""
          .;  #  Replace the first occurrence of the found 3+ digits group with this ""
              # (after the loop, the result is output implicitly)
   D          #  Duplicate the list of parts of equal adjacent digits
    7b        #  Push 7, and convert it to a binary-string: "111"
      @       #  Check for each value in the copy whether it's >= 111
       Ï      #  Only keep the parts for which this is truthy
        н     #  Pop and keep the first element (or "" if none were)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
Œɠ>2i1œPŒgFµÐL
```
[Try it online!](https://tio.run/##y0rNyan8///opJML7IwyDY9ODjg6Kd3t0NbDE3z@uxxuf7ijRzPy/39DHQVjQ0MjIyNDYx0FExNTEDAxMTHTUTA0BorCsSFQoSGIMDe3sLS0tLAwNwcA "Jelly – Try It Online")
Takes input as a list of digits, outputs as a list. Outputs `[]` if the result is empty. The TIO footer converts to/from numbers to lists (and converts `[]` to `0`)
## How it works
```
Œɠ>2i1œPŒgFµÐL - Main link. Takes a list of digits D on the left
           µÐL - Until a fixed point is reached, do the following:
Œɠ             -   Run lengths of equal adjacent elements
  >2           -   Greater than 2?
    i1         -   Find the first truthy index, i
        Œg     -   Group equal adjacent elements
      œP       -   Split, removing the element at the index i
          F    -   Flatten
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 12 bytes
```
+1`(.)\1\1+
```
[Try it online!](https://tio.run/##K0otycxL/P9f2zBBQ08zxjDGUJvr/39DLmNDQyMjI0NjLhMTUxAwMTEx4zI0BorBsaEhlyEQm5tbWFpaWliYmwMA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: Same regex as before naturally; the `1` executes it once (because Retina defaults to global search and replace) while the `+` repeats until the string no longer changes.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0, 10 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
e/(.)\1\1+
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&code=ZS8oLilcMVwxKw&input=WwoiMSIKIjMxMTIyMjEzIgoiNDQ1NTU1NTQ0NDYiCiIxMzIyMjMyMjIzMjIyMzExIgoiMTExIgoiNzc4OTk5ODg3NyIKXS1tUg)
```
e          recursively replace...
/(.)\1\1+    regex: three or more of the same character
           with empty string
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 21 bytes
```
Wa~`(.)\1\1+`a:$`.$'a
```
[Try it online!](https://tio.run/##K8gs@P8/PLEuQUNPM8YwxlA7IdFKJUFPRT3x////hsZGIGAMw4aGAA "Pip – Try It Online")
### Explanation
```
Wa~`(.)\1\1+`a:$`.$'a
                       ; a is first command-line argument (implicit)
W                      ; While
 a~                    ;  the first match in a
   `        `          ;  of this regex:
    (.)                ;   any character
       \1\1+           ;   followed by the same character 2 or more times
                       ;  exists:
               $`      ;   Portion of the string left of the match
                  $'   ;   Portion of the string right of the match
                 .     ;   Concatenate
             a:        ;   Assign back to a
                    a  ; After the loop exits, output the final value of a
```
[Answer]
# [Arturo](https://arturo-lang.io), ~~56~~ 53 bytes
```
f:$[s][(=s:<=replace s{/(.)\1\1+(.*)}"$2"s)?->s->f s]
```
[Try it](http://arturo-lang.io/playground?ca88VS)
-3 bytes thanks to @Neil
I couldn't get the regex everyone else is using to work, because it wanted to replace all instances of three or more of the same digit at the same time.
# [Arturo](https://arturo-lang.io), 69 bytes
```
g:$[a][(=a:<=flatten filter.first chunk a=>[&]=>[2<size&]a)?->a->g a]
```
[Try it](http://arturo-lang.io/playground?ca88VS)
A version that works on arrays.
[Answer]
# [Raku](https://raku.org/), 33 bytes
```
{($_,{S/(.)$0$0+//}...*eq*).tail}
```
[Try it online!](https://tio.run/##PchBCsIwFEXRrTxKkLZK0p98mwRsN@ECQgcNCBW1Oikha4914oUzuc95Xfpy33CIGEqqRTilq6plIzrRHZXKUsp2frWN/Ey3JZf3tKESAcOIFCFCrhAfKy4EQ6S1JgPm8y9m7kFmf39EoJ21znvvnLVj@QI "Perl 6 – Try It Online")
This is a sequence of successive modifications to the input string, ending when the last two elements are equal (`* eq *`). Then `tail` picks off just the last element.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 33 bytes
```
Ｗ⊕⌕⭆Φθλ⁼κ§θλ11≔Φθ∨‹λ⊖ι⁻✂θ⊖ι⊕λ¹κθθ
```
[Try it online!](https://tio.run/##VY7BCsIwEETvfkXoaQvxkHr0VFChYFHoF4R0aZeu0Sap@vcxVdB6GJhldnhjeu3MVXOMj54YBVTWOLygDdjCgWwLTXBku1rf0skBHYxScC7Ffpw0exikKENlW3x@gjxFmVJZMqL0njq76J0cHNF7YCl2@OPQXKrJTh4aJoPz638uxXLXjFdJw5s25tvVOW0MkFyMalMUxVdKxfWdXw "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Tricky without any regex or grouping primitives.
```
Ｗ⊕⌕⭆Φθλ⁼κ§θλ11
```
Map overlapping pairs of characters into `1` if equal or `0` if unequal and search for a substring match of `11`. While one is found...
```
≔Φθ∨‹λ⊖ι⁻✂θ⊖ι⊕λ¹κθ
```
... extract the characters prior to the match and all those where the substring from the match to the character contains at least two different characters.
```
θ
```
Output the final string.
[Answer]
# [V (vim)](https://github.com/DJMcMayhem/V), 6 bytes
```
òíˆ±±«
```
[Try it online!](https://tio.run/##K/v///Cmw2sPdRzaCISr//835DI2NDQyMjI05jIxMQUBExMTMy5DY6AYHBsachkCsbm5haWlpYWFuTkA "V (vim) – Try It Online")
If you check the [V wiki](https://github.com/DJMcMayhem/V/wiki/Regexes) on regexes there are a lot of shortcuts. This line basically expands to:
`while(match found){ :%s/\(.\)\1\1\+// }`
which removes the first 3 found matching characters and then repeats until there are none left.
[Answer]
# [Julia 1.0](http://julialang.org/), 53 bytes
```
!x=x==(y=replace(x,r"(.)\1\1+"=>"";count=1)) ? x : !y
```
[Try it online!](https://tio.run/##PYzhisIwEIT/9ym2@WOCVdgm2vZke/cggkSNkCPEkkSIT9@L9HRg2Zlvh/19OKsxz3OdKRPxJwUzOX0xPDeB8a044hHXjEbGDpf7wydCIeAbMnxB/Zxv9wAWrIdg9NVZbyIXFRTp5tScgSCmYKctj5OziVvRrNhqKUzB@uQ810Aj1HqBPzpGE1LJQATnyvjrzJDBZoSyKiYR27ZFuRApC1Jq95JSar/QfYEoS@0z@P7wcuX4zsV3XT8MQ9933T/6Aw "Julia 1.0 – Try It Online")
very similar to several other answers: regex, compare, recursion
[Answer]
# C function, 108 bytes
[Try it online with a driver program](https://tio.run/##TY7NCsIwEITP2acIFSFpqyh6ao0efAz1UNbaBmrMT1VEfPaYVAVPO3yzzAxOGkTvR1Jhdz3WdOX6o7xM2zX8IytVExlgW9kU2XAcp08gUdJUC5enpgRyb2VXs1TzYBEjdEA/lmVGiOBEpIWZ6LVYbEI26gfTueE5MseLGPICYuv@ahV1JbwApOrpuZKKRVHZBnP6qQ36tjvEHUB0GNmfWLIt6NjtVRJ@2ODPDzx2fhNnQ6L3fvkG)
```
char*c(char*s) {
    char *p=s,*q;
    while(*p){
        q=p;
        while(*++q==*p);
        p=q-p>=3?strcpy(p,q),c(s):q;
    }
    return s;
}
```
Here is one that hopefully meets the community standards; I'm sorry the first one didn't. I left just a few extra whitespace for clarity, hope that's OK.
[Answer]
# Excel (ms365), 124 bytes
[![enter image description here](https://i.stack.imgur.com/tjFGY.png)](https://i.stack.imgur.com/tjFGY.png)
Formula in `B1`:
```
=LET(x,SORT(TOCOL(REPT(ROW(1:9),SEQUENCE(,LEN(A1),3))),,-1),REDUCE(A1,x,LAMBDA(y,z,SUBSTITUTE(y,@SORTBY(x,FIND(x,y),),,1))))
```
**Note:** For testing, drag this down when absolute referencing is applied to `ROW($1:$9)`. Took it of in final answer to save bytes.
[Answer]
# [Haskell](https://www.haskell.org), ~~68~~ 63 bytes
```
until((==)=<<f)f
f(x:r)|(_:_:_,b)<-span(==x)r=b|1<3=x:f r
f s=s
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8Hual1lBR9HP_dQR3dXBeeAAAVl3VournQFW4WYpaUlaboWN-1L80oyczQ0bG01bW1s0jTTuNI0KqyKNGs04q2AUCdJ00a3uCAxD6igQrPINqnG0MbYtsIqTaGIK02h2LYYakxWbmJmHtDY3MQCXwUNhYKizLwSBT2FdAVNhWguBSVDJR0gaWxoaGRkZGgM5piYmIKAiYmJGZhvaAyUg2NDiA5DKG1ubmFpaWlhYW6uFAuxccECCA0A)
The function `f` recursively goes through the string and removes the first group it encounters. `until((==)=<<f)f` is short for `until(\x->f x==x)f` and applies `f` to the input string until a fixed-point is found.
#### Previous 68 bytes approach
```
(""%)
s%(x:r)|(_:_:_,b)<-span(==x)r=""%(s++b)|y<-s++[x]=y%r
s%t=s++t
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8Gual1lBR9HP_dQR3dXBeeAAAVl3VqudAVbhZilpSVpuhY3XTSUlFQ1uYpVNSqsijRrNOKtgFAnSdNGt7ggMU_D1rZCs8gWqESjWFs7SbOmEiiurR1dEWtbqVoE1FViC-SWQM3Kyk3MzAOanZtY4KugoVBQlJlXoqCnkK6gqRDNpaBkqKQDJI0NDY2MjAyNwRwTE1MQMDExMQPzDY2BcnBsCNFhCKXNzS0sLS0tLMzNlWIhNi5YAKEB)
[Answer]
# Haskell, 94 bytes
```
f xs=case break((>=3).length)$group xs of{(ys,[])->concat ys;(ys,zs)->f$concat(ys<>drop 1 zs)}
```
[Answer]
# [Scala](http://www.scala-lang.org/), 93 bytes
Golfed version. [Try it online!](https://tio.run/##hY5NSwMxEEDv@RVDThuUQNrVbVcCehE8eKgfJ@shrtMayWaXyVgspb99TVkR9GAHBiaZN28mNS64wbd9Rwzp8NAuxo4d@y5qdj4QNuJX/4N90K3j5s3Htb7DNX4K0b28Y8Nw63yEnbj8HhxecQWrItULVS/sbuMIyEopC62WZmlOcqlJE/bBNXjtKfFNLNIpSKkufJ6zllQCDAmzhdRe8LZHWNh7prx7ADj4Cdtugw/k@4Cc8rKxq2wWKDEybb6rcLRONVwRue3TyDyrGh6jZ7D5aMjR518OsfjjlFNjJpOJmUql/uXK8uwQZVmeH0PNNBt/0phjfFXN5vP5bFZVI7kX@@EL)
```
def f(s:Q):Q={var r="""(.)\1\1+""".r.replaceFirstIn(s, "");if(s==r)s else f(r)}
type Q=String
```
Ungolfed version. [Try it online!](https://tio.run/##hZBNS8QwEIbv@RVDTw1KIG21H1DQi@BBED9OrofYna2RNC3JuCiyv71mt25h9@AGEmYyzzvMO75RRo2j7obeEfhtJpS1PSnSvRWktHHYsIP6J2kjOkXNu7ateMAWvxjr3z6wIbhT2sIPA1jiCrqQxMq1voJr59T3yyO5IHnlFTxbTVDvSIAh/JKxscOuX@OT04NB8nGUSpkkiUwjzv/lsuxie7IsuzyFyjR0nK@Up/g8L8qyLIo8n8gNC8/Vfi2TzSNNcDv55PtgNrpWBmji7hUROlvBbn@BiKIoFnwhF/IshMLNAoeDUQ0uA3OoFX@VG@083drYn4cmkx29gthDXc9iDh7QeDwedq7vvG3YOP4C)
```
import scala.annotation.tailrec
import scala.util.matching.Regex
object Main {
  def main(args: Array[String]): Unit = {
    println(removeTriplets("31122213"))
    println(removeTriplets("44555554446"))
    println(removeTriplets("1322232223222311"))
    println(removeTriplets("7789998877"))
  }
  @tailrec
  def removeTriplets(s: String): String = {
    val tripletPattern: Regex = """(.)\1\1+""".r
    val replaced = tripletPattern.replaceFirstIn(s, "")
    if (s == replaced) s else removeTriplets(replaced)
  }
}
```
]