From: "Jesús Gabriel y Galán" Date: 2011-07-28T02:43:10+09:00 Subject: Re: if condition for pattern matching On Wed, Jul 27, 2011 at 6:55 PM, kotin 76 wrote: > Hi any one can reply for this? >>   1 >>   2 #!/usr/bin/env ruby >>   3 >>   5  dev2 = File.readlines("dev_string2.txt") >>   8 >>   9 >>  10 for i in dev2 >>  11 devstring=i.match(/\/dev\/[\w]+/) String#match returns a MatchData object. If you want the matched string use [0] on that. Also, I recommend using another name for i, something like line. And also use File.foreach if you are doing things to lines one by one, so that you don't read the entire file into memory. >>  12 puts devstring >>  14     if  devstring =~ %r{/dev/} then The result of the match of line 11 is obviously going to match this regular expression too, since it is a subset of the other one. >>  15     puts "pass" >>  16     end >>  17 end >> >> >> but i am not able to print pass. pleas suggest any thing to print pass So, what I'd do: File.foreach("dev_string2.txt") do |line| if m = line.match(%r{/dev/[\w]+}) puts "line #{line} passed the test" end end Hope this helps, Jesus.