How do I remove all characters, numbers and symbols except for "g" from a string and replace it with a " "?
string = "bi2gger 1is 00ggooder"
gsub is overkill here. Use String#tr:
string = "bi2gger 1is 00ggooder"
string.tr("^g", " ")
# => " gg gg "
This will return a new string. To instead modify the original string, use tr!.
See it on repl.it: https://repl.it/KJPY
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