LoginSignup
0
0

More than 5 years have passed since last update.

正規表現で特定の文字パターンに合致したある部分のみ置換

Posted at
hash = {"1"=>"3", "2"=>"4"}

'test1test2foo'.gsub(/(test)(\d+)/){ "#{$1}#{hash[$2]}" }
=> "test3test4foo"

() で括ると $ で参照できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0