[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: simple XML parsing (greedy / non-greedy
From: "Jason Voegele" <jason () jvoegele ! com>
Date: 2002-02-13 13:56:41
[Download RAW message or body]
> On Wed, 13 Feb 2002 12:06:49 GMT, David Alan Black
> <dblack@candle.superlink.net> wrote:
>
>>On Wed, 13 Feb 2002, Ron Jeffries wrote:
>>> Is there a way to tell the match operator to stop on the earliest
>>> match?
>>
>>Yes -- just use *? instead of *
>
> Thanks ... I see that that works. But I don't see why. Once the ? is in
> effect, does the whole regexp become non-greedy and quit on the first
> match? (This must be approximately the case, or it wouldn't be
> working.)
That occurrence of the * operator becomes non-greedy. Other occurrences
remain greedy unless followed by a '?'.
> What should I have read to know this?
The pickaxe book has this to say (in chapter "The Ruby Language"):
"re ?
Matches zero or one occurrence of re. The *, +, and {m,n} modifiers are
greedy by default. Append a question mark to make them minimal."
Temporary URL while rubycentral is not available:
http://rubycentral.rubynet.org/book/language.html
Jason Voegele
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic