From: joemac Date: 2010-02-23T03:45:17+09:00 Subject: Re: How do I use a variable in a regexp search string? On Jan 29, 7:38 pm, Harry Kakueki wrote: > > I dont know how to use avariablein a regex searchstring. > > ruby seems to only handle hardcoded serachstring in > > regex's.   How do you do this.   My code is below. > > Does this help? > > str = "abcdef" > searchstring = "cd" > p str =~ /#{searchstring}/ > > Harry Hi Folks, Thanks for all the helpful info. It was the #{} syntax that i was missing. This also works for the "filename as a varible" situation when parsing lots of files: filenames = ["input1", "input2", "input3"] for fname in filenames infile = File.open("#{fname}") while line = infile.gets() puts line end puts "================== end file ===================" end Very helpfull! Thanks, --JM