From: Simon Strandgaard Date: 2004-08-24T04:12:44+09:00 Subject: Re: Regexp scanning with MatchData (Re: multiple regexp matches) Wouldn't it be better to introduce a new method String#substitute. I think #gsub and #sub are too short and their name doesn't really says what they do. When I was new to ruby I recall that I had problems distinguishing between #sub and #gsub. I also want substitute to take a hash with options, like this: string.substitute(/pattern/, 'replacement', :option1=>1, :option2=>2) Possible options could be: :repeat, which says how many times that substitution should occur. For instance :repeat=>1 is equal to #sub For instance :repeat=>nil is equal to #gsub It could also be named :repeat_once=>true :literal, which tells #substitute that the content of the replacement string should be interpreted as literal.. no extra-escaping are then necessary. For instance string.substitute(/pa(tt)ern/, 'a\1b', :literal=>true) will insert 'a\1b' as literal, without inserting capture 1. Maybe there is other options. when supplied a block, then it should yield matchdata string.substitute(/pattern/) do |matchdata| matchdata[2].reverse end -- Simon Strandgaard