I need to remove some phrases from a string in Ruby. The phrases are defined inside an array. It could look like this:
remove = ["Test", "Another One", "Something Else"]
Then I want to check and remove these from a given string.
“This is a Test” => “This is a ”
“This is Another One” => “This is ”
“This is Another Two” => “This is Another Two”
Using Ruby 1.9.3 and Rail 3.2.6.
Regexp.unioncan be used to compile an array of strings (or regexpes) into a single regexp which therefore only requires a single search & replace.