From: Ben Tilly Date: 2001-01-11T12:26:48+09:00 Subject: [ruby-talk:9098] Re: Regexp for matching Ruby reg exps? 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. 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.. Cheers, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com