I'm not sure just where you're going with this, but it's possible to bite off more than 32,766 repetitions in one chunk, you just have to grind on it a bit:

c:\@Work\Perl\monks>perl -wMstrict -le "use constant K => 234_565; ;; my $s = 'xxx' . 'a' x K . 'yyy'; print substr $s, 0, 10; print substr $s, -10; print length $s; ;; use constant MAX => 32_760; ;; use integer; my $n = K / MAX; print $n; my $m = K % MAX; print $m; ;; my ($t) = $s =~ m{ xxx ((?: .{${ \MAX }}){$n} .{$m}) yyy }xms; print substr $t, 0, 10; print substr $t, -10; print length $t; " xxxaaaaaaa aaaaaaayyy 234571 7 5245 aaaaaaaaaa aaaaaaaaaa 234565
You can test this match by making the  $s string
    my $s = 'xxx' . 'a' x K . 'a' . 'yyy';
instead; the match will fail.

You can use the  m//gc modifier pairing (the  /c modifier is the new one here) to parse through your text to locate and extract the large number that is the count of the block of characters following. (Update: Please see Using regular expressions in Perl in perlretut for further explanation of the  /g and  /c modifiers.) If you can get to the point in your string at which you can extract the large number of characters you need next, you can figure the quantifier counts necessary to do a "compound counted quantifier".

That said, it might be better to go the route of an honest-to-goodness parser instead.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Matching n characters with m//g by AnomalousMonk
in thread Matching n characters with m//g by medium.dave

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.