Must be a way: escaping filter patterns

David Bovill david at architex.tv
Sun May 3 08:17:50 EDT 2009


This would "usually" work :

put "theader[1]" & cr after tList
put "th(1)" & cr after tList
put "th(2)" & cr after tList
put "th[3]" & cr after tList
put "tbody[1]" & cr after tList
put "tr[1]" & cr after tList
put "td[2]" & cr after tList
put "tra[3]" & cr after tList
put "tr[11]" & cr after tList

filter tList without "th?[0-9]]"
put tList

But it is possible that there are more than 9 rows - in which case it will
fail. What you really want to do is filter for "tr[*]" but can't because you
can't escape the "[" using "\[". Thanks for the input - just wanted to check
as there may be extra syntax not listed in the docs. I think the only real
solution is a simple repeat loop - it may even be faster than "filter", as
many test have shown previously.

So:

repeat for each line testLine in tList
    if token 1 of testLine is "th" then
        put testLine & CR after filteredList
    end if
end repeat
put filteredList

Tip:  the use of "token" instead of "word" is often really useful for
parsing output from computers - think of tokens as the equivalent of works
but for the way Rev thinks about scripts.

2009/5/3 Bernard Devlin <bdrunrev at gmail.com>

> I think this does what you require:
>
> put "tr[1]" & cr after tList
> put "tr(2)" & cr after tList
> put "tr[3]" & cr after tList
> put "tr[a]" & cr after tList
> put "td[1]" & cr after tList
> put "tra[1]" & cr after tList
> filter tList without "[t][r]?[0-9]]"
> put tList
>
> Try playing around with the 2nd letter of the filter expression, and
> using with/without.  It seems to work for me.  Unless I really don't
> understand the problem :-)



More information about the use-livecode mailing list