From: Dave Thomas Date: 2001-01-11T12:55:34+09:00 Subject: [ruby-talk:9100] Re: Regexp for matching Ruby reg exps? "Ben Tilly" writes: > Dave Thomas wrote: > > > >"Ben Tilly" 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