Dhruva Sagar wrote in post #995263:
> Something like this should do it :
>
> line.each {|l| puts l if l =~ /^(1:2)|(1:3)|(1:4)/}

That's a poor answer, because your regexp isn't anchored properly. It 
would match "5:6 abc1:3def" and "1:23 foobar" for example.

I suggest using the regexp to parse the line, then using numeric 
testing. This makes it easier to solve the other example of 3:9 to 3:31

lines.each do |line|
  if line =~ /^(\d+):(\d+)/
    major, minor = $1.to_i, $2.to_i
    puts line if major == 3 and (9..31).include?(minor)
  end
end

Note that you don't need to read the whole file in at once using 
readlines; you can read and process it one line at a time. This lets it 
work on huge files which are too big to fit into RAM.

File.open("...") do |file|
  file.each_line do |line|
    if line =~ ... as before
      ...
    end
  end
end

-- 
Posted via http://www.ruby-forum.com/.