From: Benoit Daloze Date: 2010-10-10T19:15:29+09:00 Subject: Re: Better way to remove all occurrence of matches on a String On 10 October 2010 03:39, Josh Cheek wrote: > I think gsub with an empty string is ugly too, but I am pretty confident > there is not a better way. So I am not the only to think that :) > You need to be careful, though, delete and tr don't work the way you think > they work. They are based on characters not words. They don't work with > regex because they consider the input string to be a set of characters, and > that doesn't make sense with regex. > > "abcde".delete("bd") # => "ace" > "abcde".tr("bd","12") # => "a1c2e" > Yes, I know, I proposed to add some functionality to #delete. >> I would then go for #delete, adding a special case for RegExp >> arguments, but that is not consistent with current behavior with a String. That is indeed a consistence issue. However, the semantic of "delete" (in general) seems right to me to delete/remove a part of a String (and I think is makes even more sense than the current implementation which does tr(str,'')).