From: Brian Candler Date: 2010-01-31T02:56:18+09:00 Subject: Re: How do I use a variable in a regexp search string? Josh Cheek wrote: > File.open(filename).each do |line| > if line =~ to_find > puts "This line matches: #{line}" > puts "This is what matches: #{line[to_find]}" or to avoid having to match it twice: puts "This is what matches: #{$&}" Also: puts "This is what came before: #{$`}" puts "This is what came after: #{$'}" puts "Capture 1 is #{$1}" # etc -- Posted via http://www.ruby-forum.com/.