Hi, First see the code :

a = 'foo bar baz 12 34 ret'
b = '2.bar foo tree ream baz foo'

match = Regexp.union(a.split(" "))
b.gsub(match) { |m| p m }
# >> "bar"
# >> "foo"
# >> "baz"
# >> "foo"

What I am looking for is, for every match inside the block I want to
substitute the $` to set to empty string(`""`). so that at the end of
gsub I get at last final string "bar foo baz".

But I am getting error as

a = 'foo bar baz 12 34 ret'
b = '2.bar foo tree ream baz foo'

match = Regexp.union(a.split(" "))

b.gsub(match) { |m| $`=""; m }
# ~> -:6: Can't set variable $`

With gsub how can I do that?

-- 
Posted via http://www.ruby-forum.com/.