About regexp

“aaabbxccc”.sub(/bb(.)c/, “\1.upcase”)
=> “aaax.upcasecc” # I expect ‘aaaXcc’

##############

Help Me^^

##############

From: Kyung won Cheon [mailto:[email protected]]

>> “aaabbxccc”.sub(/bb(.)c/, “\1.upcase”)

=> “aaax.upcasecc” # I expect ‘aaaXcc’

consider,

“\1.upcase”
=> “\1.upcase”

“\1”.upcase
=> “\1”

try,

“aaabbxccc”.sub(/bb(.)c/) {$1.upcase}

Kyung won Cheon wrote:

“aaabbxccc”.sub(/bb(.)c/, “\1.upcase”)
=> “aaax.upcasecc” # I expect ‘aaaXcc’

“aaabbxccc”.sub(/bb(.)c/) {$1.upcase}
=> “aaaXcc”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs