From: Ron Jeffries Date: 2002-02-13T21:54:15+09:00 Subject: Re: simple XML parsing (greedy / non-greedy 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? Thanks! Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.