Finding matched parentheses
Geoff Canyon
gcanyon at gmail.com
Fri Jul 26 03:25:51 EDT 2013
The first answer to
http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-notexplains
the disconnect between regex and HTML better than I can.
Here is a function that still requires correctness -- any unmatched ( or )
will cause it to return E with the position of the offending character --
but this routine returns *all* matched parentheses.
function strictTotalMatching S,B,E
put 0 into C
repeat with i = 1 to length(S)
if char i of S is E then
subtract 1 from C
if C < 0 then return "E" && i
put M[C],i & cr after R
else if char i of S is B then
put i into M[C]
add 1 to C
end if
end repeat
if C <> 0 then return "E" && i
sort lines of R numeric by item 1 of each
return R
end strictTotalMatching
more sneezing coming up:
put stripHTML( url("http:://www.www.com"), lineDelim("/n" ),
cos(theta))
14,84
22,44
59,68
77,83
ljksaljk((((()))))ljkadsflj
9,18
10,17
11,16
12,15
13,14
erksdfkj(klwer(jklsdfljk)lkjsdflj)lsdjkfklsd
9,34
15,25
(()(()((()(()()((())()(())))))))(()((())))
1,32
2,3
4,31
5,6
7,30
8,29
9,10
11,28
12,13
14,15
16,27
17,20
18,19
21,22
23,26
24,25
33,42
34,35
36,41
37,40
38,39
aslkjsadflj(asldkjf(jklsdf)(sjlkdf)(ljksdf))lskjdf
12,44
20,27
28,35
36,43
asdlfkj(adfjlk)sf(()())sdf(()())()sdflkj
8,15
18,23
19,20
21,22
27,32
28,29
30,31
33,34
ljkewr(((()))
8,15
18,23
19,20
21,22
27,32
28,29
30,31
33,34
23l4jk)))))
8,15
18,23
19,20
21,22
27,32
28,29
30,31
33,34
(jlksdfjkl)))
8,15
18,23
19,20
21,22
27,32
28,29
30,31
33,34
lakjsdfljasdfljkasdf
asdlfkjasdlkjf(sjkldf(sjkldf(ljksdfjl)lkjsdf(sldkjf)sldjf)slkdjf
E 64
asdflkj)ksdf)ljksdf(skldf)
E 8
More information about the use-livecode
mailing list