About String.sub

in javascript

var str = “aaa(xxx)bbb”
str.replace(/aaa((.+))bbb/, ‘AAA(’ + ‘$1’ + ‘)BBB’) // “AAA(xxx)BBB”

in ruby

How???

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

in javascript

var str = “aaa(xxx)bbb”

str.replace(/aaa((.+))bbb/, ‘AAA(’ + ‘$1’ + ‘)BBB’) //

                         watch out   ^^^^

“AAA(xxx)BBB”

in ruby How???

see http://ruby-doc.org/core/classes/String.html#M000831

Kyung won Cheon wrote:

in javascript

var str = “aaa(xxx)bbb”
str.replace(/aaa((.+))bbb/, ‘AAA(’ + ‘$1’ + ‘)BBB’) // “AAA(xxx)BBB”

in ruby

How???

str.sub!(/aaa((.+))bbb/){‘AAA(’ + $1 + ‘)BBB’}

TPR

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