Non-greedy regex?

Ken Ray kray at sonsothunder.com
Mon Aug 18 12:26:01 EDT 2003


One other suggestion... the docs for PCRE (the underlying regex engine
in Rev) is at:

http://www.pcre.org/man.txt

Have fun!

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/ 

> -----Original Message-----
> From: use-revolution-admin at lists.runrev.com 
> [mailto:use-revolution-admin at lists.runrev.com] On Behalf Of Jim Witte
> Sent: Monday, August 18, 2003 10:23 AM
> To: use-revolution at lists.runrev.com
> Subject: Non-greedy regex?
> 
> 
> Hi,
> 
>    I want to scan a long chunk of multiline text and extract 
> all lines 
> that contain the string gClassMangle (in the form of 
> '__##<classname>' 
> where ## is the length of the class name).  I'm was trying to use the 
> following script -  the basic idea is to find the first 
> match, get it, 
> then delete everything up to and including it from the text 
> and repeat.
> 
> put "__" & tClassLength & gClassName into gClassMangle
> put "(\n([^_]*)" & gClassMangle & "([^\n]*)\n)" into tPatter
> 
>    repeat forever
>      put empty into startMatch
>      put empty into endMatch
>      if matchChunk(gJumpText, tPattern, startMatach, endMatch) then
>        get char startMatch to endMatch of gJumpText
> 	answer it
>        delete char 1 to endMatch of gJumpText
>      else
> 	exit repeat
>     end if
> end repeat
> 
>    But it was matching everything from the beginning of the 
> text to the 
> end of the first match.  I realized this was because it was doing a 
> greedy match (as regex is), and so didn't just match from the nearest 
> return character (beginning of the line), but from the first return 
> character (beginning of the text).
> 
>    Is there an elegant way (without having to count back 
> characters and 
> such from endMatch) to get matchChunk to do what I want and do a 
> "non-greedy" match?
> 
> Jim
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com 
> http://lists.runrev.com/mailman/listinfo/use-> revolution
> 





More information about the use-livecode mailing list