[Templates] Converting from old template language which allows nested tags into TT template
Cees Hek
ceeshek@gmail.com
Fri, 20 Oct 2006 09:58:31 +1000
On 10/20/06, Robin Smidsr=F8d <robin@smidsrod.no> 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 =3D> "[%"}{-end =3D> "%]"}{-keep}
Cheers,
Cees