From: "Thomas, Mark - BLS CTR" Date: 2006-08-03T05:30:23+09:00 Subject: Re: parsing with delimeters ---new programmer Robert wrote: > and then somewhere in the file i have a table like this: > > IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec" > IDX_SOMETHING_SOMETHIGN "hi again" > 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 = {} > > File.foreach filename do |line| > next unless line =~ /^ID(\S+) "(.*?)"/ > table[$1] = $2 > end > > end Your regular expression does not accommodate more than one space between the key and the value, which all your lines have. Also, if there are leading spaces, you need to accommodate them. - Mark.