I have company names like "The Millard Group" and "The Chimney Corporation". I want to remove the words like "Group" or "Corporation", but only if they appear at the very end of the word. I.e. I don't want to remove them if they appear somewhere in the middle.
How can I go about doing this in Ruby? gsub
will replace the string from wherever it is, and also I have a list of about ten, so I'd rather not run gsub
ten times. It would be great if I could provide an array of these words to remove.
Try something like this:
['The Millard Group', 'The Chimney Corporation'].each do |s|
s.gsub!(/\ (Group|Corporation)$/, '')
end
You can add more words to remove in the regular expression by adding them after more |
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments