From: Daniel N Date: 2006-08-02T09:03:54+09:00 Subject: Re: newbie qustion ------=_Part_96232_17628637.1154477031801 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/2/06, Robert Smith wrote: > > I'm trying to parse a file that looks like this: > > text.... > text.... > numbers.... > > IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec" > IDX_SOMETHING_SOMETHIGN > IDY_SMOTHIENG_SOMETHIGN_SOMTHIGN "HELO world" > ID_ONE_THING "hello how are you" > ID_ONETHINGTOO "give me a number" > ID_ONEMORE_THING_ANDMORE "this are strings" > > I'm trying to create a hash table but i'm not sure what's wrong with my > delimeters: > > class Parser > > table = { } > IO.foreach('resurcefiletest') { |line| > if line =~ /^ID* (.*?) = \s* " (.*?) "/x > #if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x > table[ $1 ] = $2 > end > } > > #puts table["StaplingTitle"] > p table > > > end > > > -- > Posted via http://www.ruby-forum.com/. > > My Regex's aren't that good. To me it looks like your trying to find something in the format "stuff" = "stuff" is that correct? Assuming that it is for now. From Erics solution table = {} File.foreach filename do |line| next unless line =~ /^ID(\S+) "(.*?)"/ key, value = line.split("=") table[key] = value end ------=_Part_96232_17628637.1154477031801--