{n,}? Match at least n times, not greedily
{n,m}? Match at least n but not more than m times, not greedily
-By default, when a quantified subpattern does not allow the rest of the
+Normally when a quantified subpattern does not allow the rest of the
overall pattern to match, Perl will backtrack. However, this behaviour is
sometimes undesirable. Thus Perl provides the "possessive" quantifier form
as well.
/"(?>(?:(?>[^"\\]+)|\\.)*)"/
+Note that the possessive quantifier modifier can not be be combined
+with the non-greedy modifier. This is because it would make no sense.
+Consider the follow equivalency table:
+
+ Illegal Legal
+ ------------ ------
+ X??+ X{0}
+ X+?+ X{1}
+ X{min,max}?+ X{min}
+
=head3 Escape sequences
Because patterns are processed as double-quoted strings, the following
/* But the quantifier includes any '?', the non-greedy
* modifier, after the {}, [perl #118375]
- * Likewise the '+', the possessive modifier, and
- * they can be combined too, '?+' is the possessive
- * non-greedy modifier.
+ * Likewise the '+', the possessive modifier. They are mutually exclusive.
*/
- if (RExC_parse < RExC_end && *RExC_parse == '?' ) {
- nextchar(pRExC_state);
- }
- if (RExC_parse < RExC_end && *RExC_parse == '+' ) {
+ if (RExC_parse < RExC_end && (*RExC_parse == '?' || *RExC_parse == '+') ) {
nextchar(pRExC_state);
}
return ret;
reginsert(pRExC_state, MINMOD, ret, depth+1);
REGTAIL(pRExC_state, ret, ret + NODE_STEP_REGNODE);
}
-#ifndef REG_ALLOW_MINMOD_SUSPEND
else
-#endif
if (RExC_parse < RExC_end && *RExC_parse == '+') {
regnode *ender;
nextchar(pRExC_state);
ret->flags = 0;
ender = reg_node(pRExC_state, TAIL);
REGTAIL(pRExC_state, ret, ender);
- /*ret= ender;*/
}
if (RExC_parse < RExC_end && ISMULT2(RExC_parse)) {
#define RE_TRACK_PATTERN_OFFSETS
#endif
-/* Unless the next line is uncommented it is illegal to combine lazy
- matching with possessive matching. Frankly it doesn't make much sense
- to allow it as X*?+ matches nothing, X+?+ matches a single char only,
- and X{min,max}?+ matches min times only.
- */
-/* #define REG_ALLOW_MINMOD_SUSPEND */
-
/*
* The "internal use only" fields in regexp.h are present to pass info from
* compile to execute that permits the execute phase to run lots faster on
/(a|(bc)){0,0}+xyz/ xyz y $& xyz
/( a | ( bc ) ) {0,0} + xyz/x xyz y $& xyz
-/(a|(bc)){0,0}?xyz/ xyz y $& xyz
-/( a | ( bc ) ) {0,0} ? + xyz/x xyz y $& xyz
-
# vim: softtabstop=0 noexpandtab