On 8 Oct 2008, at 19:00, David Trasbo wrote:

>
> Frederick Cheung wrote:
>
>> I'd have a look a string scanner if I were you
>> Fred
>>
>> Sent from my iPhone
>
> That's exactly what I've been thinking of, but the real challenge is  
> to
> get the regular expression right. It needs to respect multiple
> arguments. Any suggestions?

that's the point - with stringscanner you don't need to come up with  
one giant regular expression that gets everything right

as a quick example, this

require 'strscan'
s = StringScanner.new('blah {some_partial arg1:foo arg2:bar} other  
stuff here {otherpartial arg1:baz}')

while s.scan_until /\{/
   puts "start of call"
   puts s.scan /\w+/
   s.skip /\s+/
   while  output=s.scan( /\w+:\w+/)
     puts output
     s.skip /\s+/
   end
   s.skip_until /\}/
   puts "end of call"
end

outputs

start of call
some_partial
arg1:foo
arg2:bar
end of call
start of call
otherpartial
arg1:baz
end of call


Fred

>
> -- 
> Posted via http://www.ruby-forum.com/.
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to