From: Jonas Bengtsson Date: 2002-07-04T02:47:06+09:00 Subject: Re: Regular Expression problems Hello again, Perhaps I should have mentioned that I'm a Ruby-newbie. So I am would appreciate any comments on my programming style. I have not had the time to read Programming Ruby yet (besides as a reference) thus I'm not too familiar with the Ruby-way. By the way, I really like what I've seen about Ruby so far! -- Best regards, Jonas We don't know a millionth of one percent about anything. Thomas A. Edison Wednesday, July 03, 2002, 7:25:01 PM, you wrote: > Hello, > I got a problem with regular expressions in Ruby. The closest I have > come to a solution looks like this: > _________________________________________________________________ > re = /\n(.*)( unprocessed = < > a little content > containing all sorts of > characters, even < and > > > also containing all sorts > of things > > i don't know in advance how > many of these there are but > i settle with three here > HERE > match = re.match unprocessed > while match > name = match[1] > content = match[2] > unprocessed = match[3] > puts "MATCH", "name:#{name}", "content:#{content}", > "unproc:#{unprocessed}" > match = re.match unprocessed > end > _________________________________________________________________ > Here is the output: > _________________________________________________________________ > MATCH > name:a_name > content:a little content > containing all sorts of > characters, even < and > > > also containing all sorts > of things > > i don't know in advance how > many of these there are but > i settle with three here > _________________________________________________________________ > But I want the output to look like this: > _________________________________________________________________ > MATCH > name:a_name > content:a little content > containing all sorts of > characters, even < and > > name:another_name > content:also containing all sorts > of things > name:third_name > content:i don't know in advance how > many of these there are but > i settle with three here > _________________________________________________________________ > So the problem is that the second group--(.*)--is too 'hungry' and > doesn't stop on the first occurrence of the third group--( Is it possible to change this behavior of the second group? Or are > there any better ways to solve this problem?