A good way to insert a string before a regex match in Ruby
It can be done using Ruby's "gsub", as per:
http://railsforphp.com/2008/01/17/regular-expressions-in-ruby/#preg_replace
orig_string = "all dogs go to heaven"
end_result = orig_string.gsub(/dogs/, 'nice \0')
result = subject.gsub(/(?=\bdogs\b)/, 'nice ')
The regex checks for each position in the string whether the entire word dogs
can be matched there, and then it inserts the string nice
there.
The word boundary anchors \b
ensure that we don't accidentally match hotdogs
etc.