On 10/20/06, Robin Smidsrød <[EMAIL PROTECTED]> wrote:
Josh Rosenbaum wrote:
>
> For your other problems: If you don't have many places to fix, I'd
> just use a regexp to find all the occurrences of these tags and then
> you can keep replacing them. Patterns that are used over and over you
> can do a search and replace on using a regexp, saving yourself lots of
> time. (You could also output the changes and require that you input
> "Y" for each one.)
In this particular instance, could you try and help me out with a regexp
that will work? I'm so lost sometimes when it comes to these things.
Particularely. if I have a string that containts "1234 1234 [% bla [%
xyz %] abc [% asdf %] baz %] foo [% bar %] bla bla", how do I isolate
the outer and inner tag in a smart way? I was thinking about storing the
position in the string, so that I could later insert the variable at
that point. If I try to just match on /\[\% (.*?) \%\]/ $1 will containt
"bla [% xyz", and that's not quite what I want. At the same time, if I
omit the question-mark, it will suddenly trap "bla [% xyz %] abc [% asdf
%] baz %] foo [% bar", which is not quite what I want either... As I
said, the logic of regexp sometimes eludes me...

You should look at using Regexp::Common, specifically the
Regexp::Common::balanced module.  The following should do the trick:

$RE{balanced}{-begin => "[%"}{-end => "%]"}{-keep}

Cheers,

Cees

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to