From: Glenn Jackman Date: 2009-08-15T22:45:05+09:00 Subject: Re: regexp issue on parsing from file At 2009-08-15 03:16AM, "7stud --" wrote: > 7stud -- wrote: > > Ben's regex is better, and once you've done the matching, if your regex > > has a group around the desired information, you can retrieve the desired > > information--there is no need to slice and dice the string to extract > > the information: > > > > On the other hand, if you would rather avoid regex's altogether and > stick to string slicing and dicing, you could do this: > > count = 1 > > IO.foreach("data.txt") do |line| > if line[0, 1] == "[": > first_piece = line.split(" ", 2)[0] > puts "#{count}: #{first_piece[2...-2]}" Or replace those 2 lines with: puts %Q{#{count}: #{ line.split('"')[1] }} > count += 1 > end > end > > > > --output:-- > 1: Name > 2: NameTwo > -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous