I’ve got the following: text.gsub(/(lower) (upper)/, '\1 \2')
Can I make just substitution \2 uppercase?
Something like: sed -e 's/\(abc\)/\U\1/'
Is this possible in Ruby?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
see the gsub document:
str.gsub(pattern) {|match| block } → new_str
In the block form, the current match string is passed in as a parameter, and variables such as $1, $2, $`, $&, and $’ will be set appropriately. The value returned by the block will be substituted for the match on each call.
"a lower upper b".gsub(/(lower) (upper)/){|s| $1 + " " + $2.upcase}