From: Park Heesob Date: 2006-09-29T18:43:30+09:00 Subject: Re: Regexp help Hi, >From: "Marcus Bristav" >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: Regexp help >Date: Fri, 29 Sep 2006 18:04:16 +0900 > >Hello everyone, > >I have a string of the form > >2h 3m > >or > >3m 2h > >or > >2h 3minutes > >or > >2hour 3min > >and so on > >Is there a smart regexp one liner that could produce > >[2, 3] > >If anyone types just for example > >2 > >than that should produce [2] > >for any of the above input? I know that there will be an m or an h. > >/Marcus > str = "2h 3m" # or somthing str.scan(/(\d+)(\w*)/).sort_by{|x|x[1]}.collect{|x|x[0].to_i} Regards, Park Heesob