"Ben Tilly" <ben_tilly / hotmail.com> writes:

> Dave Thomas <Dave / PragmaticProgrammer.com> wrote:
> >
> >"Ben Tilly" <ben_tilly / hotmail.com> writes:
> >
> > > Yup.  Perl's documentation agrees with me.  Can't be done
> > > in Perl with a straight regular expression.
> >
> >Not with one, perhaps, but it can with two, or three if you allow
> >escaping of a delimiter (at least in all the cases I've come across).
> 
> Depends on what you mean with 2.
> 
> Abigail has a nice substitution trick, which strips out all
> of the balanced text, and then if you have any parens left
> it was unbalanced.

Latex2html does it by expanding nested braces, starting with the
innermost, tagging each pair with a unique number. I used the same
technique in a home-grown script that converts Pragmatic Programmer
chapters from LaTeX to XML. By moving the loop out of the regexp and
making explicit, performance is perfectly fine

  1 while ($text =~ s/\{([^\{\}]*)\}/ $count++; "!!O:$count:$1!!C:$count:"/ges);


Regards


Dave