MrAutoIt MrAutoIt - 1 year ago 75
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

Answer Source

Regex literal already accepts interpolation. Just do

match = string.match(/\A>.*\(#{number}\)/)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download