Forum: Ruby about regexp...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kyung won C. (Guest)
on 2008-11-10 06:17
>> "aaabbxccc".sub(/bb(.)c/, "\\1.upcase")
=> "aaax.upcasecc"  # I expect 'aaaXcc'

##############
# Help Me^^
##############
Peña, Botp (Guest)
on 2008-11-10 06:44
(Received via mailing list)
From: Kyung won Cheon [mailto:removed_email_address@domain.invalid]
# >> "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}
Joel VanderWerf (Guest)
on 2008-11-10 06:45
(Received via mailing list)
Kyung won Cheon wrote:
>>> "aaabbxccc".sub(/bb(.)c/, "\\1.upcase")
> => "aaax.upcasecc"  # I expect 'aaaXcc'

 >>> "aaabbxccc".sub(/bb(.)c/) {$1.upcase}
=> "aaaXcc"
This topic is locked and can not be replied to.