1PERLREBACKSLASH(1)     Perl Programmers Reference Guide     PERLREBACKSLASH(1)
2
3
4

NAME

6       perlrebackslash - Perl Regular Expression Backslash Sequences and
7       Escapes
8

DESCRIPTION

10       The top level documentation about Perl regular expressions is found in
11       perlre.
12
13       This document describes all backslash and escape sequences. After
14       explaining the role of the backslash, it lists all the sequences that
15       have a special meaning in Perl regular expressions (in alphabetical
16       order), then describes each of them.
17
18       Most sequences are described in detail in different documents; the
19       primary purpose of this document is to have a quick reference guide
20       describing all backslash and escape sequences.
21
22   The backslash
23       In a regular expression, the backslash can perform one of two tasks: it
24       either takes away the special meaning of the character following it
25       (for instance, "\|" matches a vertical bar, it's not an alternation),
26       or it is the start of a backslash or escape sequence.
27
28       The rules determining what it is are quite simple: if the character
29       following the backslash is an ASCII punctuation (non-word) character
30       (that is, anything that is not a letter, digit, or underscore), then
31       the backslash just takes away any special meaning of the character
32       following it.
33
34       If the character following the backslash is an ASCII letter or an ASCII
35       digit, then the sequence may be special; if so, it's listed below. A
36       few letters have not been used yet, so escaping them with a backslash
37       doesn't change them to be special.  A future version of Perl may assign
38       a special meaning to them, so if you have warnings turned on, Perl
39       issues a warning if you use such a sequence.  [1].
40
41       It is however guaranteed that backslash or escape sequences never have
42       a punctuation character following the backslash, not now, and not in a
43       future version of Perl 5. So it is safe to put a backslash in front of
44       a non-word character.
45
46       Note that the backslash itself is special; if you want to match a
47       backslash, you have to escape the backslash with a backslash: "/\\/"
48       matches a single backslash.
49
50       [1] There is one exception. If you use an alphanumeric character as the
51           delimiter of your pattern (which you probably shouldn't do for
52           readability reasons), you have to escape the delimiter if you want
53           to match it. Perl won't warn then. See also "Gory details of
54           parsing quoted constructs" in perlop.
55
56   All the sequences and escapes
57       Those not usable within a bracketed character class (like "[\da-z]")
58       are marked as "Not in []."
59
60        \000              Octal escape sequence.  See also \o{}.
61        \1                Absolute backreference.  Not in [].
62        \a                Alarm or bell.
63        \A                Beginning of string.  Not in [].
64        \b                Word/non-word boundary. (Backspace in []).
65        \B                Not a word/non-word boundary.  Not in [].
66        \cX               Control-X
67        \C                Single octet, even under UTF-8.  Not in [].
68        \d                Character class for digits.
69        \D                Character class for non-digits.
70        \e                Escape character.
71        \E                Turn off \Q, \L and \U processing.  Not in [].
72        \f                Form feed.
73        \F                Foldcase till \E.  Not in [].
74        \g{}, \g1         Named, absolute or relative backreference.  Not in []
75        \G                Pos assertion.  Not in [].
76        \h                Character class for horizontal whitespace.
77        \H                Character class for non horizontal whitespace.
78        \k{}, \k<>, \k''  Named backreference.  Not in [].
79        \K                Keep the stuff left of \K.  Not in [].
80        \l                Lowercase next character.  Not in [].
81        \L                Lowercase till \E.  Not in [].
82        \n                (Logical) newline character.
83        \N                Any character but newline.  Experimental.  Not in [].
84        \N{}              Named or numbered (Unicode) character or sequence.
85        \o{}              Octal escape sequence.
86        \p{}, \pP         Character with the given Unicode property.
87        \P{}, \PP         Character without the given Unicode property.
88        \Q                Quote (disable) pattern metacharacters till \E.  Not
89                          in [].
90        \r                Return character.
91        \R                Generic new line.  Not in [].
92        \s                Character class for whitespace.
93        \S                Character class for non whitespace.
94        \t                Tab character.
95        \u                Titlecase next character.  Not in [].
96        \U                Uppercase till \E.  Not in [].
97        \v                Character class for vertical whitespace.
98        \V                Character class for non vertical whitespace.
99        \w                Character class for word characters.
100        \W                Character class for non-word characters.
101        \x{}, \x00        Hexadecimal escape sequence.
102        \X                Unicode "extended grapheme cluster".  Not in [].
103        \z                End of string.  Not in [].
104        \Z                End of string.  Not in [].
105
106   Character Escapes
107       Fixed characters
108
109       A handful of characters have a dedicated character escape. The
110       following table shows them, along with their ASCII code points (in
111       decimal and hex), their ASCII name, the control escape on ASCII
112       platforms and a short description.  (For EBCDIC platforms, see
113       "OPERATOR DIFFERENCES" in perlebcdic.)
114
115        Seq.  Code Point  ASCII   Cntrl   Description.
116              Dec    Hex
117         \a     7     07    BEL    \cG    alarm or bell
118         \b     8     08     BS    \cH    backspace [1]
119         \e    27     1B    ESC    \c[    escape character
120         \f    12     0C     FF    \cL    form feed
121         \n    10     0A     LF    \cJ    line feed [2]
122         \r    13     0D     CR    \cM    carriage return
123         \t     9     09    TAB    \cI    tab
124
125       [1] "\b" is the backspace character only inside a character class.
126           Outside a character class, "\b" is a word/non-word boundary.
127
128       [2] "\n" matches a logical newline. Perl converts between "\n" and your
129           OS's native newline character when reading from or writing to text
130           files.
131
132       Example
133
134        $str =~ /\t/;   # Matches if $str contains a (horizontal) tab.
135
136       Control characters
137
138       "\c" is used to denote a control character; the character following
139       "\c" determines the value of the construct.  For example the value of
140       "\cA" is chr(1), and the value of "\cb" is chr(2), etc.  The gory
141       details are in "Regexp Quote-Like Operators" in perlop.  A complete
142       list of what chr(1), etc. means for ASCII and EBCDIC platforms is in
143       "OPERATOR DIFFERENCES" in perlebcdic.
144
145       Note that "\c\" alone at the end of a regular expression (or doubled-
146       quoted string) is not valid.  The backslash must be followed by another
147       character.  That is, "\c\X" means "chr(28) . 'X'" for all characters X.
148
149       To write platform-independent code, you must use "\N{NAME}" instead,
150       like "\N{ESCAPE}" or "\N{U+001B}", see charnames.
151
152       Mnemonic: control character.
153
154       Example
155
156        $str =~ /\cK/;  # Matches if $str contains a vertical tab (control-K).
157
158       Named or numbered characters and character sequences
159
160       Unicode characters have a Unicode name and numeric code point (ordinal)
161       value.  Use the "\N{}" construct to specify a character by either of
162       these values.  Certain sequences of characters also have names.
163
164       To specify by name, the name of the character or character sequence
165       goes between the curly braces.
166
167       To specify a character by Unicode code point, use the form "\N{U+code
168       point}", where code point is a number in hexadecimal that gives the
169       code point that Unicode has assigned to the desired character.  It is
170       customary but not required to use leading zeros to pad the number to 4
171       digits.  Thus "\N{U+0041}" means "LATIN CAPITAL LETTER A", and you will
172       rarely see it written without the two leading zeros.  "\N{U+0041}"
173       means "A" even on EBCDIC machines (where the ordinal value of "A" is
174       not 0x41).
175
176       It is even possible to give your own names to characters and character
177       sequences.  For details, see charnames.
178
179       (There is an expanded internal form that you may see in debug output:
180       "\N{U+code point.code point...}".  The "..." means any number of these
181       code points separated by dots.  This represents the sequence formed by
182       the characters.  This is an internal form only, subject to change, and
183       you should not try to use it yourself.)
184
185       Mnemonic: Named character.
186
187       Note that a character or character sequence expressed as a named or
188       numbered character is considered a character without special meaning by
189       the regex engine, and will match "as is".
190
191       Example
192
193        $str =~ /\N{THAI CHARACTER SO SO}/;  # Matches the Thai SO SO character
194
195        use charnames 'Cyrillic';            # Loads Cyrillic names.
196        $str =~ /\N{ZHE}\N{KA}/;             # Match "ZHE" followed by "KA".
197
198       Octal escapes
199
200       There are two forms of octal escapes.  Each is used to specify a
201       character by its code point specified in octal notation.
202
203       One form, available starting in Perl 5.14 looks like "\o{...}", where
204       the dots represent one or more octal digits.  It can be used for any
205       Unicode character.
206
207       It was introduced to avoid the potential problems with the other form,
208       available in all Perls.  That form consists of a backslash followed by
209       three octal digits.  One problem with this form is that it can look
210       exactly like an old-style backreference (see "Disambiguation rules
211       between old-style octal escapes and backreferences" below.)  You can
212       avoid this by making the first of the three digits always a zero, but
213       that makes \077 the largest code point specifiable.
214
215       In some contexts, a backslash followed by two or even one octal digits
216       may be interpreted as an octal escape, sometimes with a warning, and
217       because of some bugs, sometimes with surprising results.  Also, if you
218       are creating a regex out of smaller snippets concatenated together, and
219       you use fewer than three digits, the beginning of one snippet may be
220       interpreted as adding digits to the ending of the snippet before it.
221       See "Absolute referencing" for more discussion and examples of the
222       snippet problem.
223
224       Note that a character expressed as an octal escape is considered a
225       character without special meaning by the regex engine, and will match
226       "as is".
227
228       To summarize, the "\o{}" form is always safe to use, and the other form
229       is safe to use for code points through \077 when you use exactly three
230       digits to specify them.
231
232       Mnemonic: 0ctal or octal.
233
234       Examples (assuming an ASCII platform)
235
236        $str = "Perl";
237        $str =~ /\o{120}/;  # Match, "\120" is "P".
238        $str =~ /\120/;     # Same.
239        $str =~ /\o{120}+/; # Match, "\120" is "P", it's repeated at least once
240        $str =~ /\120+/;    # Same.
241        $str =~ /P\053/;    # No match, "\053" is "+" and taken literally.
242        /\o{23073}/         # Black foreground, white background smiling face.
243        /\o{4801234567}/    # Raises a warning, and yields chr(4)
244
245       Disambiguation rules between old-style octal escapes and backreferences
246
247       Octal escapes of the "\000" form outside of bracketed character classes
248       potentially clash with old-style backreferences.  (see "Absolute
249       referencing" below).  They both consist of a backslash followed by
250       numbers.  So Perl has to use heuristics to determine whether it is a
251       backreference or an octal escape.  Perl uses the following rules to
252       disambiguate:
253
254       1.  If the backslash is followed by a single digit, it's a
255           backreference.
256
257       2.  If the first digit following the backslash is a 0, it's an octal
258           escape.
259
260       3.  If the number following the backslash is N (in decimal), and Perl
261           already has seen N capture groups, Perl considers this a
262           backreference.  Otherwise, it considers it an octal escape. If N
263           has more than three digits, Perl takes only the first three for the
264           octal escape; the rest are matched as is.
265
266            my $pat  = "(" x 999;
267               $pat .= "a";
268               $pat .= ")" x 999;
269            /^($pat)\1000$/;   #  Matches 'aa'; there are 1000 capture groups.
270            /^$pat\1000$/;     #  Matches 'a@0'; there are 999 capture groups
271                               #    and \1000 is seen as \100 (a '@') and a '0'
272
273       You can force a backreference interpretation always by using the
274       "\g{...}" form.  You can the force an octal interpretation always by
275       using the "\o{...}" form, or for numbers up through \077 (= 63
276       decimal), by using three digits, beginning with a "0".
277
278       Hexadecimal escapes
279
280       Like octal escapes, there are two forms of hexadecimal escapes, but
281       both start with the same thing, "\x".  This is followed by either
282       exactly two hexadecimal digits forming a number, or a hexadecimal
283       number of arbitrary length surrounded by curly braces. The hexadecimal
284       number is the code point of the character you want to express.
285
286       Note that a character expressed as one of these escapes is considered a
287       character without special meaning by the regex engine, and will match
288       "as is".
289
290       Mnemonic: hexadecimal.
291
292       Examples (assuming an ASCII platform)
293
294        $str = "Perl";
295        $str =~ /\x50/;    # Match, "\x50" is "P".
296        $str =~ /\x50+/;   # Match, "\x50" is "P", it is repeated at least once
297        $str =~ /P\x2B/;   # No match, "\x2B" is "+" and taken literally.
298
299        /\x{2603}\x{2602}/ # Snowman with an umbrella.
300                           # The Unicode character 2603 is a snowman,
301                           # the Unicode character 2602 is an umbrella.
302        /\x{263B}/         # Black smiling face.
303        /\x{263b}/         # Same, the hex digits A - F are case insensitive.
304
305   Modifiers
306       A number of backslash sequences have to do with changing the character,
307       or characters following them. "\l" will lowercase the character
308       following it, while "\u" will uppercase (or, more accurately,
309       titlecase) the character following it. They provide functionality
310       similar to the functions "lcfirst" and "ucfirst".
311
312       To uppercase or lowercase several characters, one might want to use
313       "\L" or "\U", which will lowercase/uppercase all characters following
314       them, until either the end of the pattern or the next occurrence of
315       "\E", whichever comes first. They provide functionality similar to what
316       the functions "lc" and "uc" provide.
317
318       "\Q" is used to quote (disable) pattern metacharacters, up to the next
319       "\E" or the end of the pattern. "\Q" adds a backslash to any character
320       that could have special meaning to Perl.  In the ASCII range, it quotes
321       every character that isn't a letter, digit, or underscore.  See
322       "quotemeta" in perlfunc for details on what gets quoted for non-ASCII
323       code points.  Using this ensures that any character between "\Q" and
324       "\E" will be matched literally, not interpreted as a metacharacter by
325       the regex engine.
326
327       "\F" can be used to casefold all characters following, up to the next
328       "\E" or the end of the pattern. It provides the functionality similar
329       to the "fc" function.
330
331       Mnemonic: Lowercase, Uppercase, Fold-case, Quotemeta, End.
332
333       Examples
334
335        $sid     = "sid";
336        $greg    = "GrEg";
337        $miranda = "(Miranda)";
338        $str     =~ /\u$sid/;        # Matches 'Sid'
339        $str     =~ /\L$greg/;       # Matches 'greg'
340        $str     =~ /\Q$miranda\E/;  # Matches '(Miranda)', as if the pattern
341                                     #   had been written as /\(Miranda\)/
342
343   Character classes
344       Perl regular expressions have a large range of character classes. Some
345       of the character classes are written as a backslash sequence. We will
346       briefly discuss those here; full details of character classes can be
347       found in perlrecharclass.
348
349       "\w" is a character class that matches any single word character
350       (letters, digits, Unicode marks, and connector punctuation (like the
351       underscore)).  "\d" is a character class that matches any decimal
352       digit, while the character class "\s" matches any whitespace character.
353       New in perl 5.10.0 are the classes "\h" and "\v" which match horizontal
354       and vertical whitespace characters.
355
356       The exact set of characters matched by "\d", "\s", and "\w" varies
357       depending on various pragma and regular expression modifiers.  It is
358       possible to restrict the match to the ASCII range by using the "/a"
359       regular expression modifier.  See perlrecharclass.
360
361       The uppercase variants ("\W", "\D", "\S", "\H", and "\V") are character
362       classes that match, respectively, any character that isn't a word
363       character, digit, whitespace, horizontal whitespace, or vertical
364       whitespace.
365
366       Mnemonics: word, digit, space, horizontal, vertical.
367
368       Unicode classes
369
370       "\pP" (where "P" is a single letter) and "\p{Property}" are used to
371       match a character that matches the given Unicode property; properties
372       include things like "letter", or "thai character". Capitalizing the
373       sequence to "\PP" and "\P{Property}" make the sequence match a
374       character that doesn't match the given Unicode property. For more
375       details, see "Backslash sequences" in perlrecharclass and "Unicode
376       Character Properties" in perlunicode.
377
378       Mnemonic: property.
379
380   Referencing
381       If capturing parenthesis are used in a regular expression, we can refer
382       to the part of the source string that was matched, and match exactly
383       the same thing. There are three ways of referring to such
384       backreference: absolutely, relatively, and by name.
385
386       Absolute referencing
387
388       Either "\gN" (starting in Perl 5.10.0), or "\N" (old-style) where N is
389       a positive (unsigned) decimal number of any length is an absolute
390       reference to a capturing group.
391
392       N refers to the Nth set of parentheses, so "\gN" refers to whatever has
393       been matched by that set of parentheses.  Thus "\g1" refers to the
394       first capture group in the regex.
395
396       The "\gN" form can be equivalently written as "\g{N}" which avoids
397       ambiguity when building a regex by concatenating shorter strings.
398       Otherwise if you had a regex "qr/$a$b/", and $a contained "\g1", and $b
399       contained "37", you would get "/\g137/" which is probably not what you
400       intended.
401
402       In the "\N" form, N must not begin with a "0", and there must be at
403       least N capturing groups, or else N is considered an octal escape (but
404       something like "\18" is the same as "\0018"; that is, the octal escape
405       "\001" followed by a literal digit "8").
406
407       Mnemonic: group.
408
409       Examples
410
411        /(\w+) \g1/;    # Finds a duplicated word, (e.g. "cat cat").
412        /(\w+) \1/;     # Same thing; written old-style
413        /(.)(.)\g2\g1/;  # Match a four letter palindrome (e.g. "ABBA").
414
415       Relative referencing
416
417       "\g-N" (starting in Perl 5.10.0) is used for relative addressing.  (It
418       can be written as "\g{-N".)  It refers to the Nth group before the
419       "\g{-N}".
420
421       The big advantage of this form is that it makes it much easier to write
422       patterns with references that can be interpolated in larger patterns,
423       even if the larger pattern also contains capture groups.
424
425       Examples
426
427        /(A)        # Group 1
428         (          # Group 2
429           (B)      # Group 3
430           \g{-1}   # Refers to group 3 (B)
431           \g{-3}   # Refers to group 1 (A)
432         )
433        /x;         # Matches "ABBA".
434
435        my $qr = qr /(.)(.)\g{-2}\g{-1}/;  # Matches 'abab', 'cdcd', etc.
436        /$qr$qr/                           # Matches 'ababcdcd'.
437
438       Named referencing
439
440       "\g{name}" (starting in Perl 5.10.0) can be used to back refer to a
441       named capture group, dispensing completely with having to think about
442       capture buffer positions.
443
444       To be compatible with .Net regular expressions, "\g{name}" may also be
445       written as "\k{name}", "\k<name>" or "\k'name'".
446
447       To prevent any ambiguity, name must not start with a digit nor contain
448       a hyphen.
449
450       Examples
451
452        /(?<word>\w+) \g{word}/ # Finds duplicated word, (e.g. "cat cat")
453        /(?<word>\w+) \k{word}/ # Same.
454        /(?<word>\w+) \k<word>/ # Same.
455        /(?<letter1>.)(?<letter2>.)\g{letter2}\g{letter1}/
456                                # Match a four letter palindrome (e.g. "ABBA")
457
458   Assertions
459       Assertions are conditions that have to be true; they don't actually
460       match parts of the substring. There are six assertions that are written
461       as backslash sequences.
462
463       \A  "\A" only matches at the beginning of the string. If the "/m"
464           modifier isn't used, then "/\A/" is equivalent to "/^/". However,
465           if the "/m" modifier is used, then "/^/" matches internal newlines,
466           but the meaning of "/\A/" isn't changed by the "/m" modifier. "\A"
467           matches at the beginning of the string regardless whether the "/m"
468           modifier is used.
469
470       \z, \Z
471           "\z" and "\Z" match at the end of the string. If the "/m" modifier
472           isn't used, then "/\Z/" is equivalent to "/$/"; that is, it matches
473           at the end of the string, or one before the newline at the end of
474           the string. If the "/m" modifier is used, then "/$/" matches at
475           internal newlines, but the meaning of "/\Z/" isn't changed by the
476           "/m" modifier. "\Z" matches at the end of the string (or just
477           before a trailing newline) regardless whether the "/m" modifier is
478           used.
479
480           "\z" is just like "\Z", except that it does not match before a
481           trailing newline. "\z" matches at the end of the string only,
482           regardless of the modifiers used, and not just before a newline.
483           It is how to anchor the match to the true end of the string under
484           all conditions.
485
486       \G  "\G" is usually used only in combination with the "/g" modifier. If
487           the "/g" modifier is used and the match is done in scalar context,
488           Perl remembers where in the source string the last match ended, and
489           the next time, it will start the match from where it ended the
490           previous time.
491
492           "\G" matches the point where the previous match on that string
493           ended, or the beginning of that string if there was no previous
494           match.
495
496           Mnemonic: Global.
497
498       \b, \B
499           "\b" matches at any place between a word and a non-word character;
500           "\B" matches at any place between characters where "\b" doesn't
501           match. "\b" and "\B" assume there's a non-word character before the
502           beginning and after the end of the source string; so "\b" will
503           match at the beginning (or end) of the source string if the source
504           string begins (or ends) with a word character. Otherwise, "\B" will
505           match.
506
507           Do not use something like "\b=head\d\b" and expect it to match the
508           beginning of a line.  It can't, because for there to be a boundary
509           before the non-word "=", there must be a word character immediately
510           previous.  All boundary determinations look for word characters
511           alone, not for non-words characters nor for string ends.  It may
512           help to understand how <\b> and <\B> work by equating them as
513           follows:
514
515               \b  really means    (?:(?<=\w)(?!\w)|(?<!\w)(?=\w))
516               \B  really means    (?:(?<=\w)(?=\w)|(?<!\w)(?!\w))
517
518           Mnemonic: boundary.
519
520       Examples
521
522         "cat"   =~ /\Acat/;     # Match.
523         "cat"   =~ /cat\Z/;     # Match.
524         "cat\n" =~ /cat\Z/;     # Match.
525         "cat\n" =~ /cat\z/;     # No match.
526
527         "cat"   =~ /\bcat\b/;   # Matches.
528         "cats"  =~ /\bcat\b/;   # No match.
529         "cat"   =~ /\bcat\B/;   # No match.
530         "cats"  =~ /\bcat\B/;   # Match.
531
532         while ("cat dog" =~ /(\w+)/g) {
533             print $1;           # Prints 'catdog'
534         }
535         while ("cat dog" =~ /\G(\w+)/g) {
536             print $1;           # Prints 'cat'
537         }
538
539   Misc
540       Here we document the backslash sequences that don't fall in one of the
541       categories above. These are:
542
543       \C  "\C" always matches a single octet, even if the source string is
544           encoded in UTF-8 format, and the character to be matched is a
545           multi-octet character.  "\C" was introduced in perl 5.6.  This is
546           very dangerous, because it violates the logical character
547           abstraction and can cause UTF-8 sequences to become malformed.
548
549           Mnemonic: oCtet.
550
551       \K  This appeared in perl 5.10.0. Anything matched left of "\K" is not
552           included in $&, and will not be replaced if the pattern is used in
553           a substitution. This lets you write "s/PAT1 \K PAT2/REPL/x" instead
554           of "s/(PAT1) PAT2/${1}REPL/x" or "s/(?<=PAT1) PAT2/REPL/x".
555
556           Mnemonic: Keep.
557
558       \N  This is an experimental feature new to perl 5.12.0.  It matches any
559           character that is not a newline.  It is a short-hand for writing
560           "[^\n]", and is identical to the "." metasymbol, except under the
561           "/s" flag, which changes the meaning of ".", but not "\N".
562
563           Note that "\N{...}" can mean a named or numbered character .
564
565           Mnemonic: Complement of \n.
566
567       \R  "\R" matches a generic newline; that is, anything considered a
568           linebreak sequence by Unicode. This includes all characters matched
569           by "\v" (vertical whitespace), and the multi character sequence
570           "\x0D\x0A" (carriage return followed by a line feed, sometimes
571           called the network newline; it's the end of line sequence used in
572           Microsoft text files opened in binary mode). "\R" is equivalent to
573           "(?>\x0D\x0A|\v)".  (The reason it doesn't backtrack is that the
574           sequence is considered inseparable.  That means that
575
576            "\x0D\x0A" =~ /^\R\x0A$/   # No match
577
578           fails, because the "\R" matches the entire string, and won't
579           backtrack to match just the "\x0D".)  Since "\R" can match a
580           sequence of more than one character, it cannot be put inside a
581           bracketed character class; "/[\R]/" is an error; use "\v" instead.
582           "\R" was introduced in perl 5.10.0.
583
584           Note that this does not respect any locale that might be in effect;
585           it matches according to the platform's native character set.
586
587           Mnemonic: none really. "\R" was picked because PCRE already uses
588           "\R", and more importantly because Unicode recommends such a
589           regular expression metacharacter, and suggests "\R" as its
590           notation.
591
592       \X  This matches a Unicode extended grapheme cluster.
593
594           "\X" matches quite well what normal (non-Unicode-programmer) usage
595           would consider a single character.  As an example, consider a G
596           with some sort of diacritic mark, such as an arrow.  There is no
597           such single character in Unicode, but one can be composed by using
598           a G followed by a Unicode "COMBINING UPWARDS ARROW BELOW", and
599           would be displayed by Unicode-aware software as if it were a single
600           character.
601
602           Mnemonic: eXtended Unicode character.
603
604       Examples
605
606        "\x{256}" =~ /^\C\C$/;    # Match as chr (0x256) takes 2 octets in UTF-8.
607
608        $str =~ s/foo\Kbar/baz/g; # Change any 'bar' following a 'foo' to 'baz'
609        $str =~ s/(.)\K\g1//g;    # Delete duplicated characters.
610
611        "\n"   =~ /^\R$/;         # Match, \n   is a generic newline.
612        "\r"   =~ /^\R$/;         # Match, \r   is a generic newline.
613        "\r\n" =~ /^\R$/;         # Match, \r\n is a generic newline.
614
615        "P\x{307}" =~ /^\X$/     # \X matches a P with a dot above.
616
617
618
619perl v5.16.3                      2013-03-04                PERLREBACKSLASH(1)
Impressum