Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found