Ben Tilly wrote: # 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. Small problems. On long text with # deeply nested parens it is O(n*n) performance. If you want # to nest with 2 types of balanced delimiters, good luck. If # you want to report anything about where the problem was, # oops. That text is gone. # # By contrast scan the string once, pushing and popping from a # stack and this is trivial to solve. It is O(n) runtime. # Extending to an arbitrary number of nested delimiters is # trivial. And you don't throw away text. # # This is a ridiculously simple parsing problem. It is not # suited to RE engines. Use the right tool for the job.. Hmm. And that would be what--in terms of a general purpose tool? The (not yet written) Ruby Icon module, perhaps? :-) Conrad Schneiker (This note is unofficial and subject to improvement without notice.)