collape consecutive pattern matches into one