Finding matched parentheses
dunbarx at aol.com
dunbarx at aol.com
Fri Jul 26 13:02:08 EDT 2013
I am old fashioned. And late. I think this works:
on mouseUp
answer findNests(fld 1)
end mouseUp
function findNests var
repeat with y = 1 to the number of chars in var
if char y of var = "(" then put y & return after lefts --build list of left paren
if char y of var = ")" then put y & return after rights --build list of right paren
end repeat
put 0 & return before rights
repeat with y = the number of lines of lefts down to 1
repeat with u = the number of lines of rights down to 1
if line y of lefts < line u of rights and line y of lefts > line u-1 of rights then
put line y of lefts & "," & line u of rights & return after accum
delete line y of lefts
if line u of rights <> 0 then delete line u of rights
end if
end repeat
end repeat
sort accum numeric
return accum
end findNests
The returned list orders the char numbers of the paired parens.
Craig
-----Original Message-----
From: Peter Haworth <pete at lcsql.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Fri, Jul 26, 2013 12:09 pm
Subject: Re: Finding matched parentheses
On Fri, Jul 26, 2013 at 12:10 AM, Thierry Douez <th.douez at gmail.com> wrote:
> But this one will work and match the first occurence:
>
> if matchChunk(mystring,"(\([^)]*\)).*",tstart,tEnd)
>
> Regards,
>
> Thierry
>
Nice Thierry! Doesn't handle nested parens though, but once again, that
may not be a possibility in the OP's scenario.
Pete
lcSQL Software <http://www.lcsql.com>
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list