On Mon, Jul 29, 2013 at 1:15 PM, <dunb...@aol.com> wrote:

> I read the original post as finding the "closing parenthesis ... of a pair"


You're right, sorry, forgot which regex was the one that worked.  It was
the following (which I found online so no credit to me):

\((((?>[^()]+)|(?R))*)\)

This uses regex look ahead and recursion to solve the problem.  It only
works for the first set of nested parens in a line  but since the OP's
function doesn't handle multiple sets, I assume that's not a requirement.

If it is, then here's a function that seems to work with limited testing
and subject to the performance limitations that Geoff mentioned.  Apologies
in advance for any extraneous empty line and/or asterisks that gMail might
insert into the function!

*function* getCharPairPositions pstring,pstartchar,pendchar

   *local* tstart,tend,tResults,tAdj,tregex

   *put* zero into tAdj

   *put* "\" & pstartchar & "(((?>[^" & pstartchar & pendchar &
"]+)|(?R))*)\" & pendchar into tRegex

   *repeat*

      *if* matchChunk(pstring,tRegex,tStart,tEnd) *then*

         *put* tStart-1+tAdj, tEnd+1+tAdj & *return* after tResults

         *add* (tEnd+1) to tAdj

         *delete* char 1 to tEnd+1 of pstring

      *else*

         *exit* *repeat*

      *end* *if*

   *end* *repeat*

   *return* tResults

*end* getCharPairPositions

Pete
lcSQL Software <http://www.lcsql.com>
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to