From the Fine Manual (perlre):
"(?>pattern)" WARNING: This extended regular expression fea- ture is considered highly experimental, and may be changed or deleted without notice. An "independent" subexpression, one which matches the substring that a standalone "pat- tern" would match if anchored at the given posi- tion, and it matches nothing other than this substring. This construct is useful for opti- mizations of what would otherwise be "eternal" matches, because it will not backtrack (see the section on "Backtracking"). It may also be use- ful in places where the "grab all you can, and do not give anything back" semantic is desirable. For example: "^(?>a*)ab" will never match, since "(?>a*)" (anchored at the beginning of string, as above) will match all characters "a" at the beginning of string, leaving no "a" for "ab" to match. In contrast, "a*ab" will match the same as "a+b", since the match of the subgroup "a*" is influenced by the following group "ab" (see the section on "Backtracking"). In particular, "a*" inside "a*ab" will match fewer characters than a standalone "a*", since this makes the tail match. An effect similar to "(?>pattern)" may be achieved by writing "(?=(pattern))\1". This matches the same substring as a standalone "a+", and the following "\1" eats the matched string; it therefore makes a zero-length assertion into an analogue of "(?>...)". (The difference between these two constructs is that the second one uses a capturing group, thus shifting ordi- nals of backreferences in the rest of a regular expression.) ...

-- Randal L. Schwartz, Perl hacker


In reply to •Re: Avoiding regex backtracking by merlyn
in thread Avoiding regex backtracking by Aristotle

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.