or it is the start of a backslash or escape sequence.
The rules determining what it is are quite simple: if the character
-following the backslash is a punctuation (non-word) character (that is,
-anything that is not a letter, digit or underscore), then the backslash
-just takes away the special meaning (if any) of the character following
-it.
-
-If the character following the backslash is a letter or a digit, then the
-sequence may be special; if so, it's listed below. A few letters have not
-been used yet, and escaping them with a backslash is safe for now, but a
+following the backslash is an ASCII punctuation (non-word) character (that is,
+anything that is not a letter, digit or underscore), then the backslash just
+takes away the special meaning (if any) of the character following it.
+
+If the character following the backslash is an ASCII letter or an ASCII digit,
+then the sequence may be special; if so, it's listed below. A few letters have
+not been used yet, and escaping them with a backslash is safe for now, but a
future version of Perl may assign a special meaning to it. However, if you
have warnings turned on, Perl will issue a warning if you use such a sequence.
[1].
=head2 All the sequences and escapes
+Those not usable within a bracketed character class (like C<[\da-z]>) are marked
+as C<Not in [].>
+
\000 Octal escape sequence.
- \1 Absolute backreference.
+ \1 Absolute backreference. Not in [].
\a Alarm or bell.
- \A Beginning of string.
- \b Word/non-word boundary. (Backspace in a char class).
- \B Not a word/non-word boundary.
+ \A Beginning of string. Not in [].
+ \b Word/non-word boundary. (Backspace in []).
+ \B Not a word/non-word boundary. Not in [].
\cX Control-X (X can be any ASCII character).
- \C Single octet, even under UTF-8.
+ \C Single octet, even under UTF-8. Not in [].
\d Character class for digits.
\D Character class for non-digits.
\e Escape character.
- \E Turn off \Q, \L and \U processing.
+ \E Turn off \Q, \L and \U processing. Not in [].
\f Form feed.
- \g{}, \g1 Named, absolute or relative backreference.
- \G Pos assertion.
+ \g{}, \g1 Named, absolute or relative backreference. Not in [].
+ \G Pos assertion. Not in [].
\h Character class for horizontal white space.
\H Character class for non horizontal white space.
- \k{}, \k<>, \k'' Named backreference.
- \K Keep the stuff left of \K.
- \l Lowercase next character.
- \L Lowercase till \E.
+ \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.
- \N{} Named (Unicode) character.
- \p{}, \pP Character with a Unicode property.
- \P{}, \PP Character without a Unicode property.
- \Q Quotemeta till \E.
+ \N Any character but newline. Experimental. Not in [].
+ \N{} Named or numbered (Unicode) character.
+ \p{}, \pP Character with the given Unicode property.
+ \P{}, \PP Character without the given Unicode property.
+ \Q Quotemeta till \E. Not in [].
\r Return character.
- \R Generic new line.
+ \R Generic new line. Not in [].
\s Character class for white space.
\S Character class for non white space.
\t Tab character.
- \u Titlecase next character.
- \U Uppercase till \E.
+ \u Titlecase next character. Not in [].
+ \U Uppercase till \E. Not in [].
\v Character class for vertical white space.
\V Character class for non vertical white space.
\w Character class for word characters.
\W Character class for non-word characters.
\x{}, \x00 Hexadecimal escape sequence.
- \X Unicode "extended grapheme cluster".
- \z End of string.
- \Z End of string.
+ \X Unicode "extended grapheme cluster". Not in [].
+ \z End of string. Not in [].
+ \Z End of string. Not in [].
=head2 Character Escapes
$str =~ /\cK/; # Matches if $str contains a vertical tab (control-K).
-=head3 Named characters
+=head3 Named or numbered characters
+
+All Unicode characters have a Unicode name and numeric ordinal value. Use the
+C<\N{}> construct to specify a character by either of these values.
+
+To specify by name, the name of the character goes between the curly braces.
+In this case, you have to C<use charnames> to load the Unicode names of the
+characters, otherwise Perl will complain.
+
+To specify by Unicode ordinal number, use the form
+C<\N{U+I<wide hex character>}>, where I<wide hex character> is a number in
+hexadecimal that gives the ordinal number that Unicode has assigned to the
+desired character. It is customary (but not required) to use leading zeros to
+pad the number to 4 digits. Thus C<\N{U+0041}> means
+C<Latin Capital Letter A>, and you will rarely see it written without the two
+leading zeros. C<\N{U+0041}> means C<A> even on EBCDIC machines (where the
+ordinal value of C<A> is not 0x41).
+
+It is even possible to give your own names to characters, and even to short
+sequences of characters. For details, see L<charnames>.
-All Unicode characters have a Unicode name, and characters in various scripts
-have names as well. It is even possible to give your own names to characters.
-You can use a character by name by using the C<\N{}> construct; the name of
-the character goes between the curly braces. You do have to C<use charnames>
-to load the names of the characters, otherwise Perl will complain you use
-a name it doesn't know about. For more details, see L<charnames>.
+(There is an expanded internal form that you may see in debug output:
+C<\N{U+I<wide hex character>.I<wide hex character>...}>.
+The C<...> means any number of these I<wide hex character>s separated by dots.
+This represents the sequence formed by the characters. This is an internal
+form only, subject to change, and you should not try to use it yourself.)
Mnemonic: I<N>amed character.
+Note that a character that is expressed as a named or numbered character is
+considered as a character without special meaning by the regex engine, and will
+match "as is".
+
=head4 Example
use charnames ':full'; # Loads the Unicode names.
Octal escapes consist of a backslash followed by two or three octal digits
matching the code point of the character you want to use. This allows for
-512 characters (C<\00> up to C<\777>) that can be expressed this way.
+512 characters (C<\00> up to C<\777>) that can be expressed this way (but
+anything above C<\377> is deprecated).
Enough in pre-Unicode days, but most Unicode characters cannot be escaped
this way.
A backslash sequence that starts with a backslash and is followed by a
number is an absolute reference (but be aware of the caveat mentioned above).
-If the number is I<N>, it refers to the Nth set of parenthesis - whatever
+If the number is I<N>, it refers to the Nth set of parentheses - whatever
has been matched by that set of parenthesis has to be matched by the C<\N>
as well.
Note that C<\g{}> has the potential to be ambiguous, as it could be a named
reference, or an absolute or relative reference (if its argument is numeric).
-However, names are not allowed to start with digits, nor are allowed to
+However, names are not allowed to start with digits, nor are they allowed to
contain a hyphen, so there is no ambiguity.
=head4 Examples
=head2 Assertions
-Assertions are conditions that have to be true -- they don't actually
+Assertions are conditions that have to be true; they don't actually
match parts of the substring. There are six assertions that are written as
backslash sequences.
Mnemonic: I<K>eep.
+=item \N
+
+This is a new experimental feature in perl 5.12.0. It matches any character
+that is not a newline. It is a short-hand for writing C<[^\n]>, and is
+identical to the C<.> metasymbol, except under the C</s> flag, which changes
+the meaning of C<.>, but not C<\N>.
+
+Note that C<\N{...}> can mean a
+L<named or numbered character|/Named or numbered characters>.
+
+Mnemonic: Complement of I<\n>.
+
=item \R
C<\R> matches a I<generic newline>, that is, anything that is considered
C<\X> matches quite well what normal (non-Unicode-programmer) usage
would consider a single character. As an example, consider a G with some sort
-of accent mark over it (a diacritic). There is no such single character in
-Unicode, but something like one can be constructed by using a G followed by a
-Unicode combining accent, and would be displayed by Unicode-aware software as
-if it were a single character.
+of diacritic mark, such as an arrow. There is no such single character in
+Unicode, but one can be composed by using a G followed by a Unicode "COMBINING
+UPWARDS ARROW BELOW", and would be displayed by Unicode-aware software as if it
+were a single character.
Mnemonic: eI<X>tended Unicode character.