Is there a pattern that can match repeated elements that appear more than twice in a row?
For the sake of example let's say I want to use pattern matching to delete subsequent duplicate:
l = {1,2,2,3,4};
l/.{b___,x_,x_,r___}->{b,r}
(*{1,3,4}*)
But
l = {1,2,2,2,3,4};
l/.{b___,x_,x_,r___}->{b,r}
(*{1,2,3,4}*)
I can try to use Repeated, but it doesn't seem to work:
l = {1, 2, 2, 2, 3, 4};
l /. {b___, x_, (x_) .., r___} -> {b, r}
(*{1,2,3,4}*)
Am I using it wrong?