When using gsub, is it possible to maintain case?
This is working example, possible to do this without calling gsub twice? Perhaps add case insensitive i to the regex?
'Strings'.gsub(/s/, 'z').gsub(/S/, 'Z') #=> Ztringz
Goal (obviously doesn't work):
'Strings'.gsub(/s/i, 'z') #=> Ztringz
How about using String#tr:
'Strings'.tr('sS', 'zZ')
# => "Ztringz"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With