Dear Friends,
How can I replace multiple patterns of a string in single pass.
by
Vellingiri
···
--
Posted via http://www.ruby-forum.com/.
Dear Friends,
How can I replace multiple patterns of a string in single pass.
by
Vellingiri
--
Posted via http://www.ruby-forum.com/.
Try String#gsub
Jeff
On Sep 19, 5:13 am, Vellingiri Arul <hariharan....@rediffmail.com> wrote:
Dear Friends,
How can I replace multiple patterns of a string in single pass.by
Vellingiri
--
Posted viahttp://www.ruby-forum.com/.
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
On 9/19/07, Jeff <cohen.jeff@gmail.com> wrote:
On Sep 19, 5:13 am, Vellingiri Arul <hariharan....@rediffmail.com> > wrote:
> Dear Friends,
> How can I replace multiple patterns of a string in single pass.
>
> by
> Vellingiri
> --
> Posted viahttp://www.ruby-forum.com/.Try String#gsub
Jeff