Reputation: 151
data.to_enum(: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.
Upvotes: 15
Views: 6106
Reputation: 46667
You want /#{entity[0]}/i
. #{}
is the syntax for variable insertion in strings and regexes.
Upvotes: 28