I have a string that contains a certain word pattern repeatedly. How can I keep the first occurrence, remove if it is a certain case, and substitute the rest of the pattern if it is a certain case?
rocket = "Meowth, that's right!!! Prepare for trouble meowth, and make it double. MEOWTH ftw!!!"
I want to keep the first instance of "meowth", case insensitive. The rest of "meowth" instance: if it is spelled all caps, it will be replaced with string "team rocket". Other than that, it will be removed.
rocket.gsub(/meowth/i, 'team rocket')
The code above replaces all "meowth" string instances (case insensitive). How can I keep the first instance and substitute/remove the rest of the instance?
Desired output:
rocket = "Meowth, that's right!!! Prepare for trouble, and make it double. team rocket ftw!!!"
"meowth"occur first in the string (case insensitive), even if it spelled MEOWTH, if it is first, it is left as is. Substitution/ removal happens after first occurrence.