From: joemac Date: 2010-01-30T09:50:44+09:00 Subject: How do I use a variable in a regexp search string? Hi All, I dont know how to use a variable in a regex searchstring. ruby seems to only handle hardcoded serachstring in regex's. How do you do this. My code is below. Also - how do you put a variable name in a File.open("filename.txt") statement like this: File.open(filevariable) where filevariable can be set to anything? I could not find this in the docs. Thanks, --Joe ================ snip code =============== #!/usr/bin/ruby F = "filename.txt" searchstring = ARGV[0] print "searchstring is ", searchstring, "\n" File.open("filename.txt").each { |line| # this fails puts line if line =~ searchstring # this fails puts line if line =~ /searchstring/ # this fails puts line if line =~ "searchstring" #this works # puts line }