From: Florian Gilcher Date: 2009-12-09T13:04:58+09:00 Subject: Re: which is better? On Dec 8, 2009, at 11:40 PM, Ruby Newbee wrote: > Hi, > > I want to delete the numbers in a string, for example, > > x="abcd1234" > > I have two ways: > > x.gsub! /\d+/,"" > > x[/\d+/]="" > > > Which one is better? > I personally prefer the second one. The first. It doesn't fail if the string contains no numbers: x ="abcd" x[/\d+/]="" IndexError: regexp not matched from (irb):10:in `[]=' from (irb):10 from /usr/local/bin/irb19:12:in `
' Regards, Florian