This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make utf8_to_uvchr() slightly safer
[perl5.git] / pod / perlrebackslash.pod
index 55df618..01226e6 100644 (file)
@@ -69,10 +69,8 @@ as C<Not in [].>
  \b{}, \b          Boundary. (\b is a backspace in []).
  \B{}, \B          Not a boundary.  Not in [].
  \cX               Control-X.
- \C                Single octet, even under UTF-8.  Not in [].
-                   (Deprecated)
- \d                Character class for digits.
- \D                Character class for non-digits.
+ \d                Match any digit character.
+ \D                Match any character that isn't a digit.
  \e                Escape character.
  \E                Turn off \Q, \L and \U processing.  Not in [].
  \f                Form feed.
@@ -80,31 +78,31 @@ as C<Not in [].>
  \g{}, \g1         Named, absolute or relative backreference.
                    Not in [].
  \G                Pos assertion.  Not in [].
- \h                Character class for horizontal whitespace.
- \H                Character class for non horizontal whitespace.
+ \h                Match any horizontal whitespace character.
+ \H                Match any character that isn't horizontal whitespace.
  \k{}, \k<>, \k''  Named backreference.  Not in [].
  \K                Keep the stuff left of \K.  Not in [].
  \l                Lowercase next character.  Not in [].
  \L                Lowercase till \E.  Not in [].
  \n                (Logical) newline character.
- \N                Any character but newline.  Not in [].
+ \N                Match any character but newline.  Not in [].
  \N{}              Named or numbered (Unicode) character or sequence.
  \o{}              Octal escape sequence.
- \p{}, \pP         Character with the given Unicode property.
- \P{}, \PP         Character without the given Unicode property.
+ \p{}, \pP         Match any character with the given Unicode property.
+ \P{}, \PP         Match any character without the given property.
  \Q                Quote (disable) pattern metacharacters till \E.  Not
                    in [].
  \r                Return character.
  \R                Generic new line.  Not in [].
- \s                Character class for whitespace.
- \S                Character class for non whitespace.
+ \s                Match any whitespace character.
+ \S                Match any character that isn't a whitespace.
  \t                Tab character.
  \u                Titlecase next character.  Not in [].
  \U                Uppercase till \E.  Not in [].
- \v                Character class for vertical whitespace.
- \V                Character class for non vertical whitespace.
- \w                Character class for word characters.
- \W                Character class for non-word characters.
+ \v                Match any vertical whitespace character.
+ \V                Match any character that isn't vertical whitespace
+ \w                Match any word character.
+ \W                Match any character that isn't a word character.
  \x{}, \x00        Hexadecimal escape sequence.
  \X                Unicode "extended grapheme cluster".  Not in [].
  \z                End of string.  Not in [].
@@ -531,7 +529,7 @@ Mnemonic: I<G>lobal.
 C<\b{...}>, available starting in v5.22, matches a boundary (between two
 characters, or before the first character of the string, or after the
 final character of the string) based on the Unicode rules for the
-boundary type specified inside the braces.  The currently known boundary
+boundary type specified inside the braces.  The boundary
 types are given a few paragraphs below.  C<\B{...}> matches at any place
 between characters where C<\b{...}> of the same type doesn't match.
 
@@ -539,7 +537,7 @@ C<\b> when not immediately followed by a C<"{"> matches at any place
 between a word (something matched by C<\w>) and a non-word character
 (C<\W>); C<\B> when not immediately followed by a C<"{"> matches at any
 place between characters where C<\b> doesn't match.  To get better
-word matching of natural language text, see L<\b{wb}> below.
+word matching of natural language text, see L</\b{wb}> below.
 
 C<\b>
 and C<\B> assume there's a non-word character before the beginning and after
@@ -553,7 +551,7 @@ the non-word "=", there must be a word character immediately previous.
 All plain C<\b> and C<\B> boundary determinations look for word
 characters alone, not for
 non-word characters nor for string ends.  It may help to understand how
-<\b> and <\B> work by equating them as follows:
+C<\b> and C<\B> work by equating them as follows:
 
     \b really means    (?:(?<=\w)(?!\w)|(?<!\w)(?=\w))
     \B really means    (?:(?<=\w)(?=\w)|(?<!\w)(?!\w))
@@ -561,8 +559,9 @@ non-word characters nor for string ends.  It may help to understand how
 In contrast, C<\b{...}> and C<\B{...}> may or may not match at the
 beginning and end of the line, depending on the boundary type.  These
 implement the Unicode default boundaries, specified in
+L<http://www.unicode.org/reports/tr14/> and
 L<http://www.unicode.org/reports/tr29/>.
-The boundary types currently available are:
+The boundary types are:
 
 =over
 
@@ -574,6 +573,18 @@ explained below under L</C<\X>>.  In fact, C<\X> is another way to get
 the same functionality.  It is equivalent to C</.+?\b{gcb}/>.  Use
 whichever is most convenient for your situation.
 
+=item C<\b{lb}>
+
+This matches according to the default Unicode Line Breaking Algorithm
+(L<http://www.unicode.org/reports/tr14/>), as customized in that
+document
+(L<Example 7 of revision 35|http://www.unicode.org/reports/tr14/tr14-35.html#Example7>)
+for better handling of numeric expressions.
+
+This is suitable for many purposes, but the L<Unicode::LineBreak> module
+is available on CPAN that provides many more features, including
+customization.
+
 =item C<\b{sb}>
 
 This matches a Unicode "Sentence Boundary".  This is an aid to parsing
@@ -585,19 +596,37 @@ sentence boundary.  C<\b{sb}> works with text designed for
 word-processors which wrap lines
 automatically for display, but hard-coded line boundaries are considered
 to be essentially the ends of text blocks (paragraphs really), and hence
-the ends of sententces.  C<\b{sb}> doesn't do well with text containing
+the ends of sentences.  C<\b{sb}> doesn't do well with text containing
 embedded newlines, like the source text of the document you are reading.
 Such text needs to be preprocessed to get rid of the line separators
 before looking for sentence boundaries.  Some people view this as a bug
-in the Unicode standard.
+in the Unicode standard, and this behavior is quite subject to change in
+future Perl versions.
 
 =item C<\b{wb}>
 
-This matches a Unicode "Word Boundary".  This gives better (though not
+This matches a Unicode "Word Boundary", but tailored to Perl
+expectations.  This gives better (though not
 perfect) results for natural language processing than plain C<\b>
 (without braces) does.  For example, it understands that apostrophes can
 be in the middle of words and that parentheses aren't (see the examples
-below).   More details are at L<http://www.unicode.org/reports/tr29/>.
+below).  More details are at L<http://www.unicode.org/reports/tr29/>.
+
+The current Unicode definition of a Word Boundary matches between every
+white space character.  Perl tailors this, starting in version 5.24, to
+generally not break up spans of white space, just as plain C<\b> has
+always functioned.  This allows C<\b{wb}> to be a drop-in replacement for
+C<\b>, but with generally better results for natural language
+processing.  (The exception to this tailoring is when a span of white
+space is immediately followed by something like U+0303, COMBINING TILDE.
+If the final space character in the span is a horizontal white space, it
+is broken out so that it attaches instead to the combining character.
+To be precise, if a span of white space that ends in a horizontal space
+has the character immediately following it have any of the Word
+Boundary property values "Extend", "Format" or "ZWJ", the boundary between the
+final horizontal space character and the rest of the span matches
+C<\b{wb}>.  In all other cases the boundary between two white space
+characters matches C<\B{wb}>.)
 
 =back
 
@@ -620,10 +649,9 @@ rule.
 
 It is also important to realize that these are default boundary
 definitions, and that implementations may wish to tailor the results for
-particular purposes and locales.
-
-Unicode defines a fourth boundary type, accessible through the
-L<Unicode::LineBreak> module.
+particular purposes and locales.  For example, some languages, such as
+Japanese and Thai, require dictionary lookup to accurately determine
+word boundaries.
 
 Mnemonic: I<b>oundary.
 
@@ -662,18 +690,6 @@ categories above. These are:
 
 =over 4
 
-=item \C
-
-(Deprecated.) C<\C> always matches a single octet, even if the source
-string is encoded
-in UTF-8 format, and the character to be matched is a multi-octet character.
-This is very dangerous, because it violates
-the logical character abstraction and can cause UTF-8 sequences to become malformed.
-
-Use C<utf8::encode()> instead.
-
-Mnemonic: oI<C>tet.
-
 =item \K
 
 This appeared in perl 5.10.0. Anything matched left of C<\K> is