James Edward Gray II wrote:
> On Aug 14, 2007, at 6:00 PM, anitawa wrote:
> 
>> Hello,
>>
>> I want to be able to parse a string and put them into variables.
>>
>> for example, I have this string:
>>
>> "Menu: steak_and_egg | date: 0814 | who: Anita"
>>
>> I want to parse this string to assign variables like so:
>>
>> menu = "steak_and_egg"
>> date = "0814"
>> who = "Anita"
>>
>> What would be the fastest way of doing this.
> 
> This might work if your data isn't too complicated:
> 
>  >> str = "Menu: steak_and_egg | date: 0814 | who: Anita"
> => "Menu: steak_and_egg | date: 0814 | who: Anita"
>  >> Hash[*str.scan(/(\w+):\s*(\w+)/).flatten]
> => {"date"=>"0814", "who"=>"Anita", "Menu"=>"steak_and_egg"}

Might be more general than is needed. If you know in advance that the 
"fields" are menu, date, and who, then this will do:

str = "Menu: steak_and_egg | date: 0814 | who: Anita"
pat = /Menu: (\S+) \| date: (\S+) \| who: (\S+)/

menu, date, who = str.scan(pat)[0]

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407