From: Simon Strandgaard Date: 2004-09-29T06:00:28+09:00 Subject: Re: Wish list for 2.0 On Tuesday 28 September 2004 11:26, Gavin Sinclair wrote: > On Tuesday, September 28, 2004, 5:45:08 PM, Yukihiro wrote: > > |Perhaps String#delete could take a regex as well? > > | > > | str.delete /\s/ > > > > Interesting idea. What if pattern match overwrap, e.g. > > > > str = "aabab" > > str.delete(/a./) > > > > ? Should it work as str.gsub(pat, "") ? > > That makes sense. Might as well implement it like that so it can be > documented as such. Maybe model the behavior after #scan, so that it deletes the matches that scan would have found. This way we can get very flexible deletion in case captures are being used. I propose #delete to erase those fragments that #scan matches. irb(main):011:0> 'a12bc34de56fg78hi'.scan(/(\d).{2,}?(\d)/) => [["1", "3"], ["4", "5"], ["6", "7"]] irb(main):012:0> 'a12bc34de56fg78hi'.scan(/\d.{2,}?\d/) => ["12bc3", "4de5", "6fg7"] irb(main):013:0> Lets change above 2 scan statements into delete irb(main):011:0> 'a12bc34de56fg78hi'.delete(/(\d).{2,}?(\d)/) => "a2bcdefg8hi" irb(main):012:0> 'a12bc34de56fg78hi'.delete(/\d.{2,}?\d/) => "a8hi" irb(main):013:0> Ok.. this is not the most obvious example.. but I hope you get the point. Otherwise please ask :-) -- Simon Strandgaard