KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Say I have a string : "hEY " I want to convert it to "Hey " string.gsub!(/([a-z])([A-Z]+ )/, '\1'.upcase) That is the idea I have, but it seems like the upcase method does nothing when I use it within the gsub method. Why is that? EDIT: I came up with this method: string.gsub!(/([a-z])([A-Z]+ )/) { |str| str.downcase!.capitalize! } Is there a way to do this within the regex though? I don't really understand the '\1' '\2' thing. Is that backreferencing? How does that work
Tags (comma-separated)
Save Edits
Cancel