MrAutoIt MrAutoIt - 10 months ago 32
Ruby Question

How do you use Match/Regular Expression with a variable in Ruby?

This works:

match = string.match(/\A>.*\(12345\)/)
puts match

How do I do the same thing with a variable? Something like this:

number = 12345
match = string.match("/\A>.*\(#{number}\)/")
puts match


Regex literal already accepts interpolation. Just do

match = string.match(/\A>.*\(#{number}\)/)