How can I interpolate a variable in a Ruby regex?
data.to_en开发者_开发问答um(:scan,/(#entity[0])/i).map do |m,|
p $`.size
How can I use dynamic variable in regular expression?
#entity[0]
returns a value, but in the above syntax #entity[0] is taken literally in the regex.
You want /#{entity[0]}/i
. #{}
is the syntax for variable insertion in strings and regexes.
精彩评论