From 24b23f37fefbcc71a881f6805d87449a234dc645 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Thu, 2 Nov 2006 13:35:10 +0100 Subject: Add more backtracking control verbs to regex engine (?CUT), (?ERROR) Message-ID: <9b18b3110611020335h7ea469a8g28ca483f6832816d@mail.gmail.com> p4raw-id: //depot/perl@29189 --- pod/perlre.pod | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'pod/perlre.pod') 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. + +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<(?()> -- cgit v1.2.1