Here's an example based on the pre-5.10  (?>pattern) atomic grouping. It should be fairly easily convertable to use the  + possessive quantifier modifier. (I'm using  'x' in place of  '"' because Windose command line and my REPL don't like double-quotes, but you get the idea.)

c:\@Work\Perl\monks>perl -wMstrict -le "print 'perl version: ', $]; print '------------'; ;; my $non_x_or_escaped = qr{ (?> [^x\\]{0,32766}) (?> (?> \\.){0,32766} (?> [^x\\]{0,32766})) }xms; ;; my $s = 'zx' . ('\x' x 1_000_000) . 'xz'; print 'length of test string: ', length $s; print substr($s, 0, 20), ' ... ', substr($s, -20); ;; print 'MATCHED' if $s =~ m{ (x (?> $non_x_or_escaped)* x) }xms; my $captured = $1; print 'length captured: ', length $captured; print substr($captured, 0, 20), ' ... ', substr($captured, -20); print '------------'; ;; $s = 'zx' . ('p' x 1_000_000) . '\x' . ('q' x 1_000_000) . 'xz'; print 'length of test string: ', length $s; print substr($s, 0, 20), ' ... ', substr($s, -20); ;; print 'MATCHED' if $s =~ m{ (x (?> $non_x_or_escaped)* x) }xms; $captured = $1; print 'length captured: ', length $captured; print substr($captured, 0, 20), ' ... ', substr($captured, -20); " perl version: 5.008009 ------------ length of test string: 2000004 zx\x\x\x\x\x\x\x\x\x ... \x\x\x\x\x\x\x\x\xxz MATCHED length captured: 2000002 x\x\x\x\x\x\x\x\x\x\ ... x\x\x\x\x\x\x\x\x\xx ------------ length of test string: 2000006 zxpppppppppppppppppp ... qqqqqqqqqqqqqqqqqqxz MATCHED length captured: 2000004 xppppppppppppppppppp ... qqqqqqqqqqqqqqqqqqqx


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


In reply to Re: What regex can match arbitrary-length quoted string? by AnomalousMonk
in thread What regex can match arbitrary-length quoted string? by jimav

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.