Hello, I'm using the negative lookahead assertion in a regular expression to parse tokens of a text file that start with a '>'. Some of the tokens can be very long like 500, 1000 or up to 2000 lines long. It seems that the negative lookahead assertion fails on tokens that are too many lines long. For example, if you run the following code on a MacOSX (1 GB RAM), Perl version 5.6.0 or on a Cygwin/Windows 2000 (512 MB RAM) Perl version 5.8.6, the program crashes at line 858 and line 1547, respectively. Is this a bug or it is the limit of the negative lookahead assertion?
#!/usr/bin/perl use strict; # initially, create a scalar that is 1 line long my $line = ">"."\n" x 1; my $incr = 1; while (1) { # run until it crashes while ($line =~ /^(>.*)\n(^(?!>).*\n)+/gm) { print "Number of lines: ", length($line)-1,"\n"; } # add another line $line .= "\n" x $incr; }

In reply to maximum number of lines for negative lookahead assertion (?!) by lupey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.