I’m currently studying regex (using ruby) and I would like to find the first occurrence of a non-digit character inside a word and make it capitalized.
I’ve been trying with:
word.gsub!(/\D{0,1}/) do |w|
w.capitalize
end
hoping it would just catch the first occurrence of a non-digit, but instead it returns all of the letters capitalized.
What’s the correct way to do this?
Many thanks!!!
The
gingsub!stands for “global,” meaning “every occurrence in the string.” You want regularsub!instead. That’ll just find the first. Cheers!