I came up with this and then noticed it is a variation on Anon's approach: # /. {___, x:Longest[False ...], __, y:Longest[False ...]} :> {Length[{x}], Length[{y}]} &