LoginSignup
31

More than 5 years have passed since last update.

posted at

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

変数名を#{}で囲む

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

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
What you can do with signing up
31