From: 7stud -- Date: 2009-08-15T16:16:56+09:00 Subject: Re: regexp issue on parsing from file 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]}" count += 1 end end --output:-- 1: Name 2: NameTwo -- Posted via http://www.ruby-forum.com/.