Dear Friends,
How can I replace multiple patterns of a string in single pass.
by
Vellingiri
Dear Friends,
How can I replace multiple patterns of a string in single pass.
by
Vellingiri
On Sep 19, 5:13 am, Vellingiri A. [email protected]
wrote:
Dear Friends,
How can I replace multiple patterns of a string in single pass.by
VellingiriPosted viahttp://www.ruby-forum.com/.
Try String#gsub
Jeff
On 9/19/07, Jeff [email protected] wrote:
Try String#gsub
Jeff
What you need to do is put multiple regular expressions into String#gsub
method by first calling Regexp::union. At each match you need to find
out
which regular expression did the match and provide it with the
replacement
string. So you need to use this version of gsub:
str.gsub(pattern) {|match| block } => new_str
/D
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs