This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perllocale: Clarify text
[perl5.git] / pod / perlre.pod
index 209cac7..68e18c9 100644 (file)
@@ -667,7 +667,7 @@ characters.  The C<KELVIN SIGN>, for example matches the letters "k" and
 "K"; and C<LATIN SMALL LIGATURE FF> matches the sequence "ff", which,
 if you're not prepared, might make it look like a hexadecimal constant,
 presenting another potential security issue.  See
-L<http://unicode.org/reports/tr36> for a detailed discussion of Unicode
+L<https://unicode.org/reports/tr36> for a detailed discussion of Unicode
 security issues.
 
 This modifier may be specified to be the default by C<use feature
@@ -1376,7 +1376,7 @@ an escape sequence.   Examples:
 =item C<(?^alupimnsx)>
 X<(?)> X<(?^)>
 
-One or more embedded pattern-match modifiers, to be turned on (or
+Zero or more embedded pattern-match modifiers, to be turned on (or
 turned off if preceded by C<"-">) for the remainder of the pattern or
 the remainder of the enclosing pattern group (if any).
 
@@ -1450,6 +1450,10 @@ C<(?-d:...)> and C<(?dl:...)> are fatal errors.
 Note also that the C<"p"> modifier is special in that its presence
 anywhere in a pattern has a global effect.
 
+Having zero modifiers makes this a no-op (so why did you specify it,
+unless it's generated code), and starting in v5.30, warns under L<C<use
+re 'strict'>|re/'strict' mode>.
+
 =item C<(?:I<pattern>)>
 X<(?:)>
 
@@ -1589,9 +1593,6 @@ X<look-ahead, positive> X<lookahead, positive>
 A zero-width positive lookahead assertion.  For example, C</\w+(?=\t)/>
 matches a word followed by a tab, without including the tab in C<$&>.
 
-The alphabetic forms are experimental; using them yields a warning in the
-C<experimental::alpha_assertions> category.
-
 =item C<(?!I<pattern>)>
 
 =item C<(*nla:I<pattern>)>
@@ -1612,9 +1613,6 @@ will not do what you want.  That's because the C<(?!foo)> is just saying that
 the next thing cannot be "foo"--and it's not, it's a "bar", so "foobar" will
 match.  Use lookbehind instead (see below).
 
-The alphabetic forms are experimental; using them yields a warning in the
-C<experimental::alpha_assertions> category.
-
 =item C<(?<=I<pattern>)>
 
 =item C<\K>
@@ -1629,17 +1627,38 @@ X<look-behind, positive> X<lookbehind, positive> X<\K>
 
 A zero-width positive lookbehind assertion.  For example, C</(?<=\t)\w+/>
 matches a word that follows a tab, without including the tab in C<$&>.
-Works only for fixed-width lookbehind of up to 255 characters.  Note
-that a compilation error will be generated if the assertion contains a
-multi-character match under C</i>, as that could match a single
-character, or it could match two or three, and that makes it variable
-length, which is forbidden.
-
-There is a special form of this construct, called C<\K> (available since
-Perl 5.10.0), which causes the
+
+Prior to Perl 5.30, it worked only for fixed-width lookbehind, but
+starting in that release, it can handle variable lengths from 1 to 255
+characters as an experimental feature.  The feature is enabled
+automatically if you use a variable length lookbehind assertion, but
+will raise a warning at pattern compilation time, unless turned off, in
+the C<experimental::vlb> category.  This is to warn you that the exact
+behavior is subject to change should feedback from actual use in the
+field indicate to do so; or even complete removal if the problems found
+are not practically surmountable.  You can achieve close to pre-5.30
+behavior by fatalizing warnings in this category.
+
+There is a special form of this construct, called C<\K>
+(available since Perl 5.10.0), which causes the
 regex engine to "keep" everything it had matched prior to the C<\K> and
-not include it in C<$&>. This effectively provides variable-length
-lookbehind. The use of C<\K> inside of another lookaround assertion
+not include it in C<$&>. This effectively provides non-experimental
+variable-length lookbehind of any length.
+
+And, there is a technique that can be used to handle variable length
+lookbehinds on earlier releases, and longer than 255 characters.  It is
+described in
+L<http://www.drregex.com/2019/02/variable-length-lookbehinds-actually.html>.
+
+Note that under C</i>, a few single characters match two or three other
+characters.  This makes them variable length, and the 255 length applies
+to the maximum number of characters in the match.  For
+example C<qr/\N{LATIN SMALL LETTER SHARP S}/i> matches the sequence
+C<"ss">.  Your lookbehind assertion could contain 127 Sharp S
+characters under C</i>, but adding a 128th would generate a compilation
+error, as that could match 256 C<"s"> characters in a row.
+
+The use of C<\K> inside of another lookaround assertion
 is allowed, but the behaviour is currently not well defined.
 
 For various reasons C<\K> may be significantly more efficient than the
@@ -1653,8 +1672,8 @@ can be rewritten as the much more efficient
 
   s/foo\Kbar//g;
 
-The alphabetic forms (not including C<\K> are experimental; using them
-yields a warning in the C<experimental::alpha_assertions> category.
+Use of the non-greedy modifier C<"?"> may not give you the expected
+results if it is within a capturing group within the construct.
 
 =item C<(?<!I<pattern>)>
 
@@ -1667,15 +1686,34 @@ X<(*negative_lookbehind>
 X<look-behind, negative> X<lookbehind, negative>
 
 A zero-width negative lookbehind assertion.  For example C</(?<!bar)foo/>
-matches any occurrence of "foo" that does not follow "bar".  Works
-only for fixed-width lookbehind of up to 255 characters.  Note that a
-compilation error will be generated if the assertion contains a
-multi-character match under C</i>, as that could match a single
-character, or it could match two or three, and that makes it variable
-length, which is forbidden.
-
-The alphabetic forms are experimental; using them yields a warning in the
-C<experimental::alpha_assertions> category.
+matches any occurrence of "foo" that does not follow "bar".
+
+Prior to Perl 5.30, it worked only for fixed-width lookbehind, but
+starting in that release, it can handle variable lengths from 1 to 255
+characters as an experimental feature.  The feature is enabled
+automatically if you use a variable length lookbehind assertion, but
+will raise a warning at pattern compilation time, unless turned off, in
+the C<experimental::vlb> category.  This is to warn you that the exact
+behavior is subject to change should feedback from actual use in the
+field indicate to do so; or even complete removal if the problems found
+are not practically surmountable.  You can achieve close to pre-5.30
+behavior by fatalizing warnings in this category.
+
+There is a technique that can be used to handle variable length
+lookbehinds on earlier releases, and longer than 255 characters.  It is
+described in
+L<http://www.drregex.com/2019/02/variable-length-lookbehinds-actually.html>.
+
+Note that under C</i>, a few single characters match two or three other
+characters.  This makes them variable length, and the 255 length applies
+to the maximum number of characters in the match.  For
+example C<qr/\N{LATIN SMALL LETTER SHARP S}/i> matches the sequence
+C<"ss">.  Your lookbehind assertion could contain 127 Sharp S
+characters under C</i>, but adding a 128th would generate a compilation
+error, as that could match 256 C<"s"> characters in a row.
+
+Use of the non-greedy modifier C<"?"> may not give you the expected
+results if it is within a capturing group within the construct.
 
 =back
 
@@ -2277,9 +2315,6 @@ matches, but
 
 does not.
 
-The alphabetic form (C<(*atomic:...)>) is experimental; using it
-yields a warning in the C<experimental::alpha_assertions> category.
-
 =item C<(?[ ])>
 
 See L<perlrecharclass/Extended Bracketed Character Classes>.
@@ -2544,21 +2579,18 @@ you can write either of these:
 
 In Taiwan, Japan, and Korea, it is common for text to have a mixture of
 characters from their native scripts and base Chinese.  Perl follows
-Unicode's UTS 39 (L<http://unicode.org/reports/tr39/>) Unicode Security
+Unicode's UTS 39 (L<https://unicode.org/reports/tr39/>) Unicode Security
 Mechanisms in allowing such mixtures.  For example, the Japanese scripts
 Katakana and Hiragana are commonly mixed together in practice, along
 with some Chinese characters, and hence are treated as being in a single
 script run by Perl.
 
-The rules used for matching decimal digits are somewhat different.  Many
+The rules used for matching decimal digits are slightly stricter.  Many
 scripts have their own sets of digits equivalent to the Western C<0>
 through C<9> ones.  A few, such as Arabic, have more than one set.  For
 a string to be considered a script run, all digits in it must come from
-the same set, as determined by the first digit encountered. The ASCII
-C<[0-9]> are accepted as being in any script, even those that have their
-own set.  This is because these are often used in commerce even in such
-scripts.  But any mixing of the ASCII and other digits will cause the
-sequence to not be a script run, failing the match.  As an example,
+the same set of ten, as determined by the first digit encountered.
+As an example,
 
  qr/(*script_run: \d+ \b )/x
 
@@ -2579,23 +2611,19 @@ accent of some type.  These are considered to be in the script of the
 master character, and so never cause a script run to not match.
 
 The other one is "Common".  This consists of mostly punctuation, emoji,
-and characters used in mathematics and music, and the ASCII digits C<0>
-through C<9>.  These characters can appear intermixed in text in many of
-the world's scripts.  These also don't cause a script run to not match,
-except any ASCII digits encountered have to obey the decimal digit rules
-described above.
+and characters used in mathematics and music, the ASCII digits C<0>
+through C<9>, and full-width forms of these digits.  These characters
+can appear intermixed in text in many of the world's scripts.  These
+also don't cause a script run to not match.  But like other scripts, all
+digits in a run must come from the same set of 10.
 
 This construct is non-capturing.  You can add parentheses to I<pattern>
 to capture, if desired.  You will have to do this if you plan to use
 L</(*ACCEPT) (*ACCEPT:arg)> and not have it bypass the script run
 checking.
 
-This feature is experimental, and the exact syntax and details of
-operation are subject to change; using it yields a warning in the
-C<experimental::script_run> category.
-
 The C<Script_Extensions> property as modified by UTS 39
-(L<http://unicode.org/reports/tr39/>) is used as the basis for this
+(L<https://unicode.org/reports/tr39/>) is used as the basis for this
 feature.
 
 To summarize,
@@ -2630,7 +2658,7 @@ All characters in the sequence come from the Common script and/or the
 Inherited script and/or a single other script.
 
 The script of a character is determined by the C<Script_Extensions>
-property as modified by UTS 39 (L<http://unicode.org/reports/tr39/>), as
+property as modified by UTS 39 (L<https://unicode.org/reports/tr39/>), as
 described above.
 
 =item 3
@@ -2644,8 +2672,8 @@ consecutive digits.
 
 =head2 Special Backtracking Control Verbs
 
-These special patterns are generally of the form C<(*I<VERB>:I<ARG>)>. Unless
-otherwise stated the I<ARG> argument is optional; in some cases, it is
+These special patterns are generally of the form C<(*I<VERB>:I<arg>)>. Unless
+otherwise stated the I<arg> argument is optional; in some cases, it is
 mandatory.
 
 Any pattern containing a special backtracking verb that allows an argument
@@ -2653,9 +2681,9 @@ has the special behaviour that when executed it sets the current package's
 C<$REGERROR> and C<$REGMARK> variables. When doing so the following
 rules apply:
 
-On failure, the C<$REGERROR> variable will be set to the I<ARG> value of the
+On failure, the C<$REGERROR> variable will be set to the I<arg> value of the
 verb pattern, if the verb was involved in the failure of the match. If the
-I<ARG> part of the pattern was omitted, then C<$REGERROR> will be set to the
+I<arg> part of the pattern was omitted, then C<$REGERROR> will be set to the
 name of the last C<(*MARK:I<NAME>)> pattern executed, or to TRUE if there was
 none. Also, the C<$REGMARK> variable will be set to FALSE.
 
@@ -2834,7 +2862,7 @@ is not the same as
 as after matching the I<A> but failing on the I<B> the C<(*THEN)> verb will
 backtrack and try I<C>; but the C<(*PRUNE)> verb will simply fail.
 
-=item C<(*COMMIT)> C<(*COMMIT:I<args>)>
+=item C<(*COMMIT)> C<(*COMMIT:I<arg>)>
 X<(*COMMIT)>
 
 This is the Perl 6 "commit pattern" C<< <commit> >> or C<:::>. It's a