LoginSignup
34
31

More than 5 years have passed since last update.

正規表現のパターンを変数であたえるとき

Posted at

変数名を#{}で囲む

qiita.rb
object = "こんにちは 世界です。"
jouken = "こんにちは"
goku = "さようなら"
p object.gsub(/#{jouken}/,goku)
34
31
2

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
34
31