[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Txr-users] use regex in filter?

From: Kaz Kylheku
Subject: Re: [Txr-users] use regex in filter?
Date: Fri, 12 Jul 2013 08:41:45 -0700
User-agent: Roundcube Webmail/0.4

On Thu, 11 Jul 2013 19:11:07 +0800, 苏灵 <address@hidden> wrote:
> I am new to TXR. Txr is a powerful tool that make things simple.
> filter is amazing, but when i want to use regex in filter to do some
> replacement, i don't know how to implement. 
>  Is it possible to use regex in filter? If it is ,how?

Not currently. The filter stuff has its own algorithm based on tries.
This would
have to be extended to encompass regexes. I have some ideas how to do
maybe I can make it a priority for the next release.

There is already a hybridization going on in the trie data structure in
that a node of the tree can be a function which takes over the matching
from that node downward. This allows the :fromhtml filter to work,
has to be able to recognize sequences of digits for the character
which takes the form: &#<digits>; 

Regex filtering can be done using TXR Lisp, via the regsub function,
but that's not satisfactory if you want to replace multiple regexes
with multiple replacements.

A pattern-matching function can be used for filtering also. Look for
the section "Function Filters" in the manual.  The idea is that you can
write a two-argument pattern function which analyzes the first argument
and binds the second one to some output. This can then be used in
with the (:fun <function-name>) syntax. But this has to handle the
text in one call, performing all necessary replacements on it.

> BTW, some directives is not easy to understand, more example will
> help.

That's right; the goal so far had been just to make the documentation
in terms of feature coverage. Examples are lacking in many places.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]