diff options
author | Yves Orton <demerphq@gmail.com> | 2006-11-02 13:35:10 +0100 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-11-02 12:26:47 +0000 |
commit | 24b23f37fefbcc71a881f6805d87449a234dc645 (patch) | |
tree | d7d4e050bd8ca74d9f9ca74ded7a2eb0f91e56b7 /pod/perlre.pod | |
parent | 68d3ba501ed4219f9b173a4c9e373c024180d087 (diff) | |
download | perl-24b23f37fefbcc71a881f6805d87449a234dc645.tar.gz |
Add more backtracking control verbs to regex engine (?CUT), (?ERROR)
Message-ID: <9b18b3110611020335h7ea469a8g28ca483f6832816d@mail.gmail.com>
p4raw-id: //depot/perl@29189
Diffstat (limited to 'pod/perlre.pod')
-rw-r--r-- | pod/perlre.pod | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pod/perlre.pod b/pod/perlre.pod index 4e683a37f4..bce72914fb 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -1094,6 +1094,48 @@ Any number of C<(?COMMIT)> assertions may be used in a pattern. See also C<< (?>pattern) >> and possessive quantifiers for other ways to control backtracking. +=item C<(?CUT)> +X<(?CUT)> + +This zero-width pattern is similar to C<(?COMMIT)>, except that on +failure it also signifies that whatever text that was matched leading +up to the C<(?CUT)> pattern cannot match, I<even from another +starting point>. + +Compare the following to the examples in C<(?COMMIT)>, note the string +is twice as long: + + 'aaabaaab'=~/a+b?(?CUT)(?{print "$&\n"; $count++})(?FAIL)/; + print "Count=$count\n"; + +outputs + + aaab + aaab + Count=2 + +Once the 'aaab' at the start of the string has matched and the C<(?CUT)> +executed the next startpoint will be where the cursor was when the +C<(?CUT)> was executed. + +=item C<(?ERROR)> +X<(?ERROR)> + +This zero-width pattern is similar to C<(?CUT)> except that it causes +the match to fail outright. No attempts to match will occur again. + + 'aaabaaab'=~/a+b?(?ERROR)(?{print "$&\n"; $count++})(?FAIL)/; + print "Count=$count\n"; + +outputs + + aaab + Count=1 + +In other words, once the C<(?ERROR)> has been entered and then pattern +does not match then the regex engine will not try any further matching at +all on the rest of the string. + =item C<(?(condition)yes-pattern|no-pattern)> X<(?()> |