I'm looking for a way to substitute words and phrases in a string from a hash. I know that this can be done elegantly in Ruby > 1.9 for single words:
a = "every good boy does fine"
h = {"every" => "all","boy" => "girl", "fine" =>"well" }
a.gsub(/\w+/) { |m| h.fetch(m,m)}
https://stackoverflow.com/a/20650800/4530434
However this doesn't work if the phrase I want substituted is more than one word. What I want is something like this, ideally working with arbitrarily long string substitutions, but I'd settle for two (or three) word phrases.
a = "I love the eighteen nineties"
b = {"eighteen nineties" => "1890's" }
# => "I love the 1890's"
I've tried fiddling with the Regexp in the code above, but couldn't get anythig to work.