in reply to Re: Re^2: A NOT in regular expressions (why [^%>]?)
in thread A NOT in regular expressions

Thanks for all the replies, everyone. I had considered look-aheads but didn't want to go there because there is supposed to be a way to do this that works well and doesn't require these new regex features.

How would you get Perl 4 or sed to match C comments? I've read Mastering Regular Expressions but not recently and no longer have a copy.

I realize that the author doesn't like nesting of quantifiers like that. But avoiding the quantifiers also means that the outer construct has to match more times. Since Perl stops after that happens 32k times, the extra quantifier can make a real improvement. I prefer to prevent rampant back-tracking on failure by making the regex very explicit so that back-tracking won't happen. If I can't do that, then I consider solving the problem in smaller pieces.

                - tye
  • Comment on Re^4: A NOT in regular expressions (no new features?)

Replies are listed 'Best First'.
Re: Re^4: A NOT in regular expressions (no new features?)
by tilly (Archbishop) on May 14, 2003 at 18:40 UTC
    Alternate solutions. The simplest is to use a minimal match: m/<%.*?%>/s. However you can get by with basic features with something like: m/<%[^%]*(%+[^%>][^%]*)*%+>/. That should, possibly with appropriate syntax adjustments, work in any RE engine worthy of the name.