>>>>> "darren" == darren chamberlain <[EMAIL PROTECTED]> writes:
darren> * Bill Moseley <moseley at hank.org> [2003-07-31 08:22]:
>> Any way to use captured text in the replace filter? For example if I
>> wanted to limit repeating chars to three chars:
>>
>> [% foo | replace('(.)\1{3,}', $1$1$1 ) %]
darren> Unfortunately, no. No one's come up with a decent way to do
darren> it. If you feel ambitious, poke at Template::Stash (around
darren> line 71 or so).
You can do it slowly and ugly-y by a .match loop. :)
[%-
MACRO onlythree (str) BLOCK;
newstr = "";
WHILE (matches = str.match('(.*?)(.)\2{3,}(.*)'));
str = matches.2;
newstr = newstr _ matches.0 _ matches.1 _ matches.1 _ matches.1;
END;
newstr _ str;
END;
-%]
[% onlythree("hello world xxxxxxx howdy yyyyyyy and some more") %]
Turing Completeness. Yes. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates