Wolfram Language (Mathematica), 3131 29 bytes
Attributes@f=Flat
a__~f~a__=f@af[a___,b__,b__,c___]=f[a,b,c]
Input [characters...]
. Return the characters of the reduced string, wrapped in f
.
NonCommutativeMultiply
(**
) is a conveniently Flat
undefined operator. Unfortunately, it needs to be Unprotect
ed before we can add a definition. Try it online!