From: "Jean-François Trân" Date: 2008-03-07T04:10:49+09:00 Subject: Re: Sequence reduction 2008/3/6, Stephen Fickas : > I'd like to take a string like that below > > "0011122234667889" > > and reduce to > > "012346789" > > I can see ways to do it for a single digit, but > not all in one fell swoop: > > "0011122234667889".gsub(/1{2,}/, "1") > #reduce seq (2 or more) of 1s to > single 1 > > "0011122234667889".gsub(/1+/, "1") #1 or more 1s to single 1 My first try would be : "0011122234667889".gsub /(\d)\1+/, '\1' -- Jean-François.