Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私たちはこれを知っています:
p '%s' % "test" #=> "test"
しかし、これを行うことは可能ですか:
s = "string" s[/#{%s}/] % "test"
まあ、いつでもこれを行うことができます:
s[Regexp.new("%s" % "test")]
文字列に特別な意味を持つ文字を含めることができる場合は、Regexp.escape事前に使用してください。また、正規表現に直接補間することもできます:
Regexp.escape
s = "test" /#{s}/ #=> /test/