From: boris Date: 2002-02-13T22:04:57+09:00 Subject: Re: simple XML parsing (greedy / non-greedy On Wed, Feb 13, 2002 at 09:54:15PM +0900, Ron Jeffries muttered... : On Wed, 13 Feb 2002 12:06:49 GMT, David Alan Black : wrote: : : >On Wed, 13 Feb 2002, Ron Jeffries wrote: : > : >> Suppose I had this text : >> : >> 'this is athis is a also' : >> : >> and I wanted to write a regexp that would match the tag .. and : >> return : >> : >> 'this is a' : >> (not 'this is athis is a also') : >> : >> I'd sort of like to use a pattern like : >> : >> Regexp.new( '(.*)' ), but this is greedy and matches as far as it : >> can. : >> : >> 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.) : : Anyway, thanks ... if I treat it as magic it'll work. : : What should I have read to know this? : It makes the klene star non-greedy (*). Regards, Chris -- +------------------------------------------------------------------+ | Chris Ross | chris@darkrock.co.uk | ctr@ferite.org | | | http://www.darkrock.co.uk | http://www.ferite.org | +------------------------------------------------------------------+ "Happiness is a computer that does not smoke."