Hi --

On Thu, 4 Jul 2002 nobu.nokada / softhome.net wrote:

> Hi,
>
> At Thu, 4 Jul 2002 02:25:01 +0900,
> Jonas Bengtsson wrote:
> > So the problem is that the second group--(.*)--is too 'hungry' and
> > doesn't stop on the first occurrence of the third group--(<name:.*).
> >
> > Is it possible to change this behavior of the second group? Or are
> > there any better ways to solve this problem?
>
>   re = /<name: ([a-zA-Z_]+)>\n(.*?)(<name:.*|\z)/m
>
> Or:
>   re = /<name: ([a-zA-Z_]+)>\n(.*?)(?=<name:|\z)/m
>   while match = re.match(unprocessed)
>     name = match[1]
>     content = match[2]
>     unprocessed = match.post_match	# <--
>     puts "MATCH", "name:#{name}", "content:#{content}"
>   end

One more variant, using the mighty #scan:

  re = /<name: ([a-zA-Z_]+)>\n(.*?)(?=<name:|\z)/m
  unprocessed.scan(re) do |n,c|
    puts "MATCH:","name:#{n}","content:#{c}"
  end

(Jonas: contrary to your hand-made output, you *did* want "MATCH"
three times, didn't you? :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav