summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-01-07 19:05:06 -0700
committerKarl Williamson <khw@cpan.org>2021-01-20 06:51:49 -0700
commit20420ba9e016c0a7de5df27b5ab1fefd7902a766 (patch)
treed157a6a79342d614f6a88a226edaa639b57a20f4 /pod
parenta25b770c008a6e530595a4b555443e2b65289a65 (diff)
downloadperl-20420ba9e016c0a7de5df27b5ab1fefd7902a766.tar.gz
Allow empty lower bound in /{,n}/
This change has been planned for a long time, bringing Perl into parity with similar languages, but it took many deprecation cycles to be able to reach the point where it could safely go in. This fixes GH #18264
Diffstat (limited to 'pod')
-rw-r--r--pod/perldelta.pod7
-rw-r--r--pod/perlre.pod11
-rw-r--r--pod/perlrequick.pod4
-rw-r--r--pod/perlreref.pod3
-rw-r--r--pod/perlretut.pod23
5 files changed, 36 insertions, 12 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 54089b8e0b..d7072d17c5 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -12,7 +12,12 @@ This document describes differences between the 5.33.5 release and the
If you are upgrading from an earlier release such as 5.33.4, first read
L<perl5335delta>, which describes differences between 5.33.4 and 5.33.5.
-=head1 Modules and Pragmata
+=head1 Core Enhancements
+
+=head2 C<qr/{,n}/> is now accepted.
+
+An empty lower bound is now accepted for regular expression quantifiers,
+like C<{,3}>
=head2 Updated Modules and Pragmata
diff --git a/pod/perlre.pod b/pod/perlre.pod
index 308b792532..83a3b08dfa 100644
--- a/pod/perlre.pod
+++ b/pod/perlre.pod
@@ -865,6 +865,7 @@ X<metacharacter> X<quantifier> X<*> X<+> X<?> X<{n}> X<{n,}> X<{n,m}>
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
+ {,n} Match at most n times
{n,m} Match at least n but not more than m times
(If a non-escaped curly bracket occurs in a context other than one of
@@ -891,13 +892,14 @@ allowing the rest of the pattern to match. If you want it to match the
minimum number of times possible, follow the quantifier with a C<"?">. Note
that the meanings don't change, just the "greediness":
X<metacharacter> X<greedy> X<greediness>
-X<?> X<*?> X<+?> X<??> X<{n}?> X<{n,}?> X<{n,m}?>
+X<?> X<*?> X<+?> X<??> X<{n}?> X<{n,}?> X<{,n}?> X<{n,m}?>
*? Match 0 or more times, not greedily
+? Match 1 or more times, not greedily
?? Match 0 or 1 time, not greedily
{n}? Match exactly n times, not greedily (redundant)
{n,}? Match at least n times, not greedily
+ {,n}? Match at most n times, not greedily
{n,m}? Match at least n but not more than m times, not greedily
Normally when a quantified subpattern does not allow the rest of the
@@ -910,6 +912,7 @@ as well.
?+ Match 0 or 1 time and give nothing back
{n}+ Match exactly n times and give nothing back (redundant)
{n,}+ Match at least n times and give nothing back
+ {,n}+ Match at most n times and give nothing back
{n,m}+ Match at least n but not more than m times and give nothing back
For instance,
@@ -2334,9 +2337,9 @@ see L</Combining RE Pieces>.
A fundamental feature of regular expression matching involves the
notion called I<backtracking>, which is currently used (when needed)
-by all regular non-possessive expression quantifiers, namely C<"*">, C<*?>, C<"+">,
-C<+?>, C<{n,m}>, and C<{n,m}?>. Backtracking is often optimized
-internally, but the general principle outlined here is valid.
+by all regular non-possessive expression quantifiers, namely C<"*">,
+C<*?>, C<"+">, C<+?>, C<{n,m}>, and C<{n,m}?>. Backtracking is often
+optimized internally, but the general principle outlined here is valid.
For a regular expression to match, the I<entire> regular expression must
match, not just part of it. So if the beginning of a pattern containing a
diff --git a/pod/perlrequick.pod b/pod/perlrequick.pod
index 5c5030c24c..6a70e9cd0d 100644
--- a/pod/perlrequick.pod
+++ b/pod/perlrequick.pod
@@ -363,6 +363,10 @@ C<a{n,}> = match at least C<n> or more times
=item *
+C<a{,n}> = match C<n> times or fewer
+
+=item *
+
C<a{n}> = match exactly C<n> times
=back
diff --git a/pod/perlreref.pod b/pod/perlreref.pod
index e54093ccf1..4074e01b8a 100644
--- a/pod/perlreref.pod
+++ b/pod/perlreref.pod
@@ -217,6 +217,7 @@ Quantifiers are greedy by default and match the B<longest> leftmost.
{n,m} {n,m}? {n,m}+ Must occur at least n times
but no more than m times
{n,} {n,}? {n,}+ Must occur at least n times
+ {,n} {,n}? {,n}+ Must occur at most n times
{n} {n}? {n}+ Must occur exactly n times
* *? *+ 0 or more times (same as {0,})
+ +? ++ 1 or more times (same as {1,})
@@ -226,8 +227,6 @@ The possessive forms (new in Perl 5.10) prevent backtracking: what gets
matched by a pattern with a possessive quantifier will not be backtracked
into, even if that causes the whole match to fail.
-There is no quantifier C<{,n}>. That's currently illegal.
-
=head2 EXTENDED CONSTRUCTS
(?#text) A comment
diff --git a/pod/perlretut.pod b/pod/perlretut.pod
index cb4654f552..70b16f1ddb 100644
--- a/pod/perlretut.pod
+++ b/pod/perlretut.pod
@@ -1048,6 +1048,10 @@ C<a{n,}> means: match at least C<n> or more times
=item *
+C<a{,n}> means: match at most C<n> times, or fewer
+
+=item *
+
C<a{n}> means: match exactly C<n> times
=back
@@ -1223,6 +1227,11 @@ possible
=item *
+C<a{,n}?> means: match at most C<n> times, but as few times as
+possible
+
+=item *
+
C<a{n}?> means: match exactly C<n> times. Because we match exactly
C<n> times, C<a{n}?> is equivalent to C<a{n}> and is just there for
notational consistency.
@@ -1390,8 +1399,12 @@ for C<a{0,1}+>
=item *
C<a{n,}+> means: match at least C<n> times, but as many times as possible,
-and don't give anything up. C<a*+> is short for C<a{0,}+> and C<a++> is
-short for C<a{1,}+>.
+and don't give anything up. C<a++> is short for C<a{1,}+>.
+
+=item *
+
+C<a{,n}+> means: match as many times as possible up to at most C<n>
+times, and don't give anything up. C<a*+> is short for C<a{0,}+>.
=item *
@@ -2243,9 +2256,9 @@ Starting with this section, we will be discussing Perl's set of
I<extended patterns>. These are extensions to the traditional regular
expression syntax that provide powerful new tools for pattern
matching. We have already seen extensions in the form of the minimal
-matching constructs C<??>, C<*?>, C<+?>, C<{n,m}?>, and C<{n,}?>. Most
-of the extensions below have the form C<(?char...)>, where the
-C<char> is a character that determines the type of extension.
+matching constructs C<??>, C<*?>, C<+?>, C<{n,m}?>, C<{n,}?>, and
+C<{,n}?>. Most of the extensions below have the form C<(?char...)>,
+where the C<char> is a character that determines the type of extension.
The first extension is an embedded comment C<(?#text)>. This embeds a
comment into the regular expression without affecting its meaning. The