hash = {"1"=>"3", "2"=>"4"}
'test1test2foo'.gsub(/(test)(\d+)/){ "#{$1}#{hash[$2]}" }
=> "test3test4foo"
()
で括ると $
で参照できる。
More than 5 years have passed since last update.
hash = {"1"=>"3", "2"=>"4"}
'test1test2foo'.gsub(/(test)(\d+)/){ "#{$1}#{hash[$2]}" }
=> "test3test4foo"
()
で括ると $
で参照できる。
Register as a new user and use Qiita more conveniently