From: John Smith Date: 2010-09-17T23:32:15+09:00 Subject: Printing part what's found with a regex Hi everyone, I'm trying to build a program that filters certain lines through regular expressions. In the seconde regular expression I wan to be able to print only what's within the \(\w+\) part of the expression? How do I do this? counter = 0 if inFile.nil? == false File.foreach(inFile) do |line| if line =~ /^[^%\s*^%]/ if line =~ /(?!%)\w+\s+\(\w+\)/ puts "found in line #{counter+1} " puts line end end counter = counter + 1 end end Regards, Ted. -- Posted via http://www.ruby-forum.com/.