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/