# Newbie qustion

**URL:** <https://www.ruby-forum.com/t/newbie-qustion/100941>\
**Category:** Ruby\
**Created:** [August 2, 2006, 12:33am UTC](https://www.ruby-forum.com/t/newbie-qustion/100941 "2006-08-02T00:33:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 2, 2006, 12:33am UTC](https://www.ruby-forum.com/t/newbie-qustion/100941/1 "2006-08-02T00:33:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 2, 2006, 2:07am UTC](https://www.ruby-forum.com/t/newbie-qustion/100941/2 "2006-08-02T02:07:35Z")

</div>

On 8/2/06, Robert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ID\_ONE\_THING “hello how are you”  
> if line =~ /^ID\* (._?) = \s_ " (.\*?) "/x
> 
> –  
> Posted via [http://www.ruby-forum.com/](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
