From: Hector Date: 2006-03-03T11:30:55+09:00 Subject: Re: gsub wrapper Timothy Goddard wrote: > str = "We love Ruby" > puts str.gsub(/We (\w+) \w+/, 'Why do we \1 it?') > puts str.gsub(/(\w+)$/, "it because \\1 allows us to do cool stuff!") First, thanks to everyone for your input. But I wanted to be able to invoke 'gsub' with end-user specified strings for both the regex pattern and the replacement string. If the end-user regex patern contains regexp groupings and the replacement string contains any of $1, $2, ... $9, these variables($1,$2...) will not get interpolated because they are within a string object. The non-block version of gsub works fine but I need more flexibility. Maybe a sample invokation of the script would help explain what I want. Here's a sample: INPUT_STRING = 'This is getting to be a bear!' script invokation -> snr.rb -regex'(\W)+(\w\w)(\W)+' -replacement'$1->$2<-$3' Should display -> 'This ->is<- getting ->to<- ->be<- a bear!' I'm finding it hard to explain exactly what it is I am looking for - simple concept but difficult for me to explain. Again, thank you for your help. Hector -- Posted via http://www.ruby-forum.com/.