This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Fix comment
[perl5.git] / pod / perlrecharclass.pod
1 =head1 NAME
2 X<character class>
3
4 perlrecharclass - Perl Regular Expression Character Classes
5
6 =head1 DESCRIPTION
7
8 The top level documentation about Perl regular expressions
9 is found in L<perlre>.
10
11 This manual page discusses the syntax and use of character
12 classes in Perl regular expressions.
13
14 A character class is a way of denoting a set of characters
15 in such a way that one character of the set is matched.
16 It's important to remember that: matching a character class
17 consumes exactly one character in the source string. (The source
18 string is the string the regular expression is matched against.)
19
20 There are three types of character classes in Perl regular
21 expressions: the dot, backslash sequences, and the form enclosed in square
22 brackets.  Keep in mind, though, that often the term "character class" is used
23 to mean just the bracketed form.  Certainly, most Perl documentation does that.
24
25 =head2 The dot
26
27 The dot (or period), C<.> is probably the most used, and certainly
28 the most well-known character class. By default, a dot matches any
29 character, except for the newline. That default can be changed to
30 add matching the newline by using the I<single line> modifier: either
31 for the entire regular expression with the C</s> modifier, or
32 locally with C<(?s)>.  (The C<L</\N>> backslash sequence, described
33 below, matches any character except newline without regard to the
34 I<single line> modifier.)
35
36 Here are some examples:
37
38  "a"  =~  /./       # Match
39  "."  =~  /./       # Match
40  ""   =~  /./       # No match (dot has to match a character)
41  "\n" =~  /./       # No match (dot does not match a newline)
42  "\n" =~  /./s      # Match (global 'single line' modifier)
43  "\n" =~  /(?s:.)/  # Match (local 'single line' modifier)
44  "ab" =~  /^.$/     # No match (dot matches one character)
45
46 =head2 Backslash sequences
47 X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
48 X<\N> X<\v> X<\V> X<\h> X<\H>
49 X<word> X<whitespace>
50
51 A backslash sequence is a sequence of characters, the first one of which is a
52 backslash.  Perl ascribes special meaning to many such sequences, and some of
53 these are character classes.  That is, they match a single character each,
54 provided that the character belongs to the specific set of characters defined
55 by the sequence.
56
57 Here's a list of the backslash sequences that are character classes.  They
58 are discussed in more detail below.  (For the backslash sequences that aren't
59 character classes, see L<perlrebackslash>.)
60
61  \d             Match a decimal digit character.
62  \D             Match a non-decimal-digit character.
63  \w             Match a "word" character.
64  \W             Match a non-"word" character.
65  \s             Match a whitespace character.
66  \S             Match a non-whitespace character.
67  \h             Match a horizontal whitespace character.
68  \H             Match a character that isn't horizontal whitespace.
69  \v             Match a vertical whitespace character.
70  \V             Match a character that isn't vertical whitespace.
71  \N             Match a character that isn't a newline.
72  \pP, \p{Prop}  Match a character that has the given Unicode property.
73  \PP, \P{Prop}  Match a character that doesn't have the Unicode property
74
75 =head3 \N
76
77 C<\N>, available starting in v5.12, like the dot, matches any
78 character that is not a newline. The difference is that C<\N> is not influenced
79 by the I<single line> regular expression modifier (see L</The dot> above).  Note
80 that the form C<\N{...}> may mean something completely different.  When the
81 C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
82 character that many times.  For example, C<\N{3}> means to match 3
83 non-newlines; C<\N{5,}> means to match 5 or more non-newlines.  But if C<{...}>
84 is not a legal quantifier, it is presumed to be a named character.  See
85 L<charnames> for those.  For example, none of C<\N{COLON}>, C<\N{4F}>, and
86 C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
87 names are respectively C<COLON>, C<4F>, and C<F4>.
88
89 =head3 Digits
90
91 C<\d> matches a single character considered to be a decimal I<digit>.
92 If the C</a> regular expression modifier is in effect, it matches [0-9].
93 Otherwise, it
94 matches anything that is matched by C<\p{Digit}>, which includes [0-9].
95 (An unlikely possible exception is that under locale matching rules, the
96 current locale might not have C<[0-9]> matched by C<\d>, and/or might match
97 other characters whose code point is less than 256.  The only such locale
98 definitions that are legal would be to match C<[0-9]> plus another set of
99 10 consecutive digit characters;  anything else would be in violation of
100 the C language standard, but Perl doesn't currently assume anything in
101 regard to this.)
102
103 What this means is that unless the C</a> modifier is in effect C<\d> not
104 only matches the digits '0' - '9', but also Arabic, Devanagari, and
105 digits from other languages.  This may cause some confusion, and some
106 security issues.
107
108 Some digits that C<\d> matches look like some of the [0-9] ones, but
109 have different values.  For example, BENGALI DIGIT FOUR (U+09EA) looks
110 very much like an ASCII DIGIT EIGHT (U+0038).  An application that
111 is expecting only the ASCII digits might be misled, or if the match is
112 C<\d+>, the matched string might contain a mixture of digits from
113 different writing systems that look like they signify a number different
114 than they actually do.  L<Unicode::UCD/num()> can
115 be used to safely
116 calculate the value, returning C<undef> if the input string contains
117 such a mixture.
118
119 What C<\p{Digit}> means (and hence C<\d> except under the C</a>
120 modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
121 C<\p{General_Category=Digit}>.  Starting with Unicode version 4.1, this
122 is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
123 But Unicode also has a different property with a similar name,
124 C<\p{Numeric_Type=Digit}>, which matches a completely different set of
125 characters.  These characters are things such as C<CIRCLED DIGIT ONE>
126 or subscripts, or are from writing systems that lack all ten digits.
127
128 The design intent is for C<\d> to exactly match the set of characters
129 that can safely be used with "normal" big-endian positional decimal
130 syntax, where, for example 123 means one 'hundred', plus two 'tens',
131 plus three 'ones'.  This positional notation does not necessarily apply
132 to characters that match the other type of "digit",
133 C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
134
135 The Tamil digits (U+0BE6 - U+0BEF) can also legally be
136 used in old-style Tamil numbers in which they would appear no more than
137 one in a row, separated by characters that mean "times 10", "times 100",
138 etc.  (See L<http://www.unicode.org/notes/tn21>.)
139
140 Any character not matched by C<\d> is matched by C<\D>.
141
142 =head3 Word characters
143
144 A C<\w> matches a single alphanumeric character (an alphabetic character, or a
145 decimal digit); or a connecting punctuation character, such as an
146 underscore ("_"); or a "mark" character (like some sort of accent) that
147 attaches to one of those.  It does not match a whole word.  To match a
148 whole word, use C<\w+>.  This isn't the same thing as matching an
149 English word, but in the ASCII range it is the same as a string of
150 Perl-identifier characters.
151
152 =over
153
154 =item If the C</a> modifier is in effect ...
155
156 C<\w> matches the 63 characters [a-zA-Z0-9_].
157
158 =item otherwise ...
159
160 =over
161
162 =item For code points above 255 ...
163
164 C<\w> matches the same as C<\p{Word}> matches in this range.  That is,
165 it matches Thai letters, Greek letters, etc.  This includes connector
166 punctuation (like the underscore) which connect two words together, or
167 diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
168 are generally used to add auxiliary markings to letters.
169
170 =item For code points below 256 ...
171
172 =over
173
174 =item if locale rules are in effect ...
175
176 C<\w> matches the platform's native underscore character plus whatever
177 the locale considers to be alphanumeric.
178
179 =item if Unicode rules are in effect ...
180
181 C<\w> matches exactly what C<\p{Word}> matches.
182
183 =item otherwise ...
184
185 C<\w> matches [a-zA-Z0-9_].
186
187 =back
188
189 =back
190
191 =back
192
193 Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
194
195 There are a number of security issues with the full Unicode list of word
196 characters.  See L<http://unicode.org/reports/tr36>.
197
198 Also, for a somewhat finer-grained set of characters that are in programming
199 language identifiers beyond the ASCII range, you may wish to instead use the
200 more customized L</Unicode Properties>, C<\p{ID_Start}>,
201 C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>.  See
202 L<http://unicode.org/reports/tr31>.
203
204 Any character not matched by C<\w> is matched by C<\W>.
205
206 =head3 Whitespace
207
208 C<\s> matches any single character considered whitespace.
209
210 =over
211
212 =item If the C</a> modifier is in effect ...
213
214 In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that
215 is, the horizontal tab,
216 the newline, the form feed, the carriage return, and the space.
217 Starting in Perl v5.18, it also matches the vertical tab, C<\cK>.
218 See note C<[1]> below for a discussion of this.
219
220 =item otherwise ...
221
222 =over
223
224 =item For code points above 255 ...
225
226 C<\s> matches exactly the code points above 255 shown with an "s" column
227 in the table below.
228
229 =item For code points below 256 ...
230
231 =over
232
233 =item if locale rules are in effect ...
234
235 C<\s> matches whatever the locale considers to be whitespace.
236
237 =item if Unicode rules are in effect ...
238
239 C<\s> matches exactly the characters shown with an "s" column in the
240 table below.
241
242 =item otherwise ...
243
244 C<\s> matches [\t\n\f\r ] and, starting in Perl
245 v5.18, the vertical tab, C<\cK>.
246 (See note C<[1]> below for a discussion of this.)
247 Note that this list doesn't include the non-breaking space.
248
249 =back
250
251 =back
252
253 =back
254
255 Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
256
257 Any character not matched by C<\s> is matched by C<\S>.
258
259 C<\h> matches any character considered horizontal whitespace;
260 this includes the platform's space and tab characters and several others
261 listed in the table below.  C<\H> matches any character
262 not considered horizontal whitespace.  They use the platform's native
263 character set, and do not consider any locale that may otherwise be in
264 use.
265
266 C<\v> matches any character considered vertical whitespace;
267 this includes the platform's carriage return and line feed characters (newline)
268 plus several other characters, all listed in the table below.
269 C<\V> matches any character not considered vertical whitespace.
270 They use the platform's native character set, and do not consider any
271 locale that may otherwise be in use.
272
273 C<\R> matches anything that can be considered a newline under Unicode
274 rules. It can match a multi-character sequence. It cannot be used inside
275 a bracketed character class; use C<\v> instead (vertical whitespace).
276 It uses the platform's
277 native character set, and does not consider any locale that may
278 otherwise be in use.
279 Details are discussed in L<perlrebackslash>.
280
281 Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
282 the same characters, without regard to other factors, such as the active
283 locale or whether the source string is in UTF-8 format.
284
285 One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true
286 starting in Perl v5.18, but prior to that, the sole difference was that the
287 vertical tab (C<"\cK">) was not matched by C<\s>.
288
289 The following table is a complete listing of characters matched by
290 C<\s>, C<\h> and C<\v> as of Unicode 6.3.
291
292 The first column gives the Unicode code point of the character (in hex format),
293 the second column gives the (Unicode) name. The third column indicates
294 by which class(es) the character is matched (assuming no locale is in
295 effect that changes the C<\s> matching).
296
297  0x0009        CHARACTER TABULATION   h s
298  0x000a              LINE FEED (LF)    vs
299  0x000b             LINE TABULATION    vs  [1]
300  0x000c              FORM FEED (FF)    vs
301  0x000d        CARRIAGE RETURN (CR)    vs
302  0x0020                       SPACE   h s
303  0x0085             NEXT LINE (NEL)    vs  [2]
304  0x00a0              NO-BREAK SPACE   h s  [2]
305  0x1680            OGHAM SPACE MARK   h s
306  0x2000                     EN QUAD   h s
307  0x2001                     EM QUAD   h s
308  0x2002                    EN SPACE   h s
309  0x2003                    EM SPACE   h s
310  0x2004          THREE-PER-EM SPACE   h s
311  0x2005           FOUR-PER-EM SPACE   h s
312  0x2006            SIX-PER-EM SPACE   h s
313  0x2007                FIGURE SPACE   h s
314  0x2008           PUNCTUATION SPACE   h s
315  0x2009                  THIN SPACE   h s
316  0x200a                  HAIR SPACE   h s
317  0x2028              LINE SEPARATOR    vs
318  0x2029         PARAGRAPH SEPARATOR    vs
319  0x202f       NARROW NO-BREAK SPACE   h s
320  0x205f   MEDIUM MATHEMATICAL SPACE   h s
321  0x3000           IDEOGRAPHIC SPACE   h s
322
323 =over 4
324
325 =item [1]
326
327 Prior to Perl v5.18, C<\s> did not match the vertical tab.
328 C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did.
329
330 =item [2]
331
332 NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
333 on the rules in effect.  See
334 L<the beginning of this section|/Whitespace>.
335
336 =back
337
338 =head3 Unicode Properties
339
340 C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
341 Unicode properties.  One letter property names can be used in the C<\pP> form,
342 with the property name following the C<\p>, otherwise, braces are required.
343 When using braces, there is a single form, which is just the property name
344 enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
345 which means to match if the property "name" for the character has that particular
346 "value".
347 For instance, a match for a number can be written as C</\pN/> or as
348 C</\p{Number}/>, or as C</\p{Number=True}/>.
349 Lowercase letters are matched by the property I<Lowercase_Letter> which
350 has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
351 C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
352 (the underscores are optional).
353 C</\pLl/> is valid, but means something different.
354 It matches a two character string: a letter (Unicode property C<\pL>),
355 followed by a lowercase C<l>.
356
357 If locale rules are not in effect, the use of
358 a Unicode property will force the regular expression into using Unicode
359 rules, if it isn't already.
360
361 Note that almost all properties are immune to case-insensitive matching.
362 That is, adding a C</i> regular expression modifier does not change what
363 they match.  There are two sets that are affected.  The first set is
364 C<Uppercase_Letter>,
365 C<Lowercase_Letter>,
366 and C<Titlecase_Letter>,
367 all of which match C<Cased_Letter> under C</i> matching.
368 The second set is
369 C<Uppercase>,
370 C<Lowercase>,
371 and C<Titlecase>,
372 all of which match C<Cased> under C</i> matching.
373 (The difference between these sets is that some things, such as Roman
374 numerals, come in both upper and lower case, so they are C<Cased>, but
375 aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
376 actually C<Letter_Number>s.)
377 This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
378 of which under C</i> match C<PosixAlpha>.
379
380 For more details on Unicode properties, see L<perlunicode/Unicode
381 Character Properties>; for a
382 complete list of possible properties, see
383 L<perluniprops/Properties accessible through \p{} and \P{}>,
384 which notes all forms that have C</i> differences.
385 It is also possible to define your own properties. This is discussed in
386 L<perlunicode/User-Defined Character Properties>.
387
388 Unicode properties are defined (surprise!) only on Unicode code points.
389 Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats
390 non-Unicode code points (those above the legal Unicode maximum of
391 0x10FFFF) as if they were typical unassigned Unicode code points.
392
393 Prior to v5.20, Perl raised a warning and made all matches fail on
394 non-Unicode code points.  This could be somewhat surprising:
395
396  chr(0x110000) =~ \p{ASCII_Hex_Digit=True}     # Fails on Perls < v5.20.
397  chr(0x110000) =~ \p{ASCII_Hex_Digit=False}    # Also fails on Perls
398                                                # < v5.20
399
400 Even though these two matches might be thought of as complements, until
401 v5.20 they were so only on Unicode code points.
402
403 =head4 Examples
404
405  "a"  =~  /\w/      # Match, "a" is a 'word' character.
406  "7"  =~  /\w/      # Match, "7" is a 'word' character as well.
407  "a"  =~  /\d/      # No match, "a" isn't a digit.
408  "7"  =~  /\d/      # Match, "7" is a digit.
409  " "  =~  /\s/      # Match, a space is whitespace.
410  "a"  =~  /\D/      # Match, "a" is a non-digit.
411  "7"  =~  /\D/      # No match, "7" is not a non-digit.
412  " "  =~  /\S/      # No match, a space is not non-whitespace.
413
414  " "  =~  /\h/      # Match, space is horizontal whitespace.
415  " "  =~  /\v/      # No match, space is not vertical whitespace.
416  "\r" =~  /\v/      # Match, a return is vertical whitespace.
417
418  "a"  =~  /\pL/     # Match, "a" is a letter.
419  "a"  =~  /\p{Lu}/  # No match, /\p{Lu}/ matches upper case letters.
420
421  "\x{0e0b}" =~ /\p{Thai}/  # Match, \x{0e0b} is the character
422                            # 'THAI CHARACTER SO SO', and that's in
423                            # Thai Unicode class.
424  "a"  =~  /\P{Lao}/ # Match, as "a" is not a Laotian character.
425
426 It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
427 complete numbers or words. To match a number (that consists of digits),
428 use C<\d+>; to match a word, use C<\w+>.  But be aware of the security
429 considerations in doing so, as mentioned above.
430
431 =head2 Bracketed Character Classes
432
433 The third form of character class you can use in Perl regular expressions
434 is the bracketed character class.  In its simplest form, it lists the characters
435 that may be matched, surrounded by square brackets, like this: C<[aeiou]>.
436 This matches one of C<a>, C<e>, C<i>, C<o> or C<u>.  Like the other
437 character classes, exactly one character is matched.* To match
438 a longer string consisting of characters mentioned in the character
439 class, follow the character class with a L<quantifier|perlre/Quantifiers>.  For
440 instance, C<[aeiou]+> matches one or more lowercase English vowels.
441
442 Repeating a character in a character class has no
443 effect; it's considered to be in the set only once.
444
445 Examples:
446
447  "e"  =~  /[aeiou]/        # Match, as "e" is listed in the class.
448  "p"  =~  /[aeiou]/        # No match, "p" is not listed in the class.
449  "ae" =~  /^[aeiou]$/      # No match, a character class only matches
450                            # a single character.
451  "ae" =~  /^[aeiou]+$/     # Match, due to the quantifier.
452
453  -------
454
455 * There are two exceptions to a bracketed character class matching a
456 single character only.  Each requires special handling by Perl to make
457 things work:
458
459 =over
460
461 =item *
462
463 When the class is to match caselessly under C</i> matching rules, and a
464 character that is explicitly mentioned inside the class matches a
465 multiple-character sequence caselessly under Unicode rules, the class
466 will also match that sequence.  For example, Unicode says that the
467 letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss>
468 under C</i> rules.  Thus,
469
470  'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i             # Matches
471  'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i    # Matches
472
473 For this to happen, the class must not be inverted (see L</Negation>)
474 and the character must be explicitly specified, and not be part of a
475 multi-character range (not even as one of its endpoints).  (L</Character
476 Ranges> will be explained shortly.) Therefore,
477
478  'ss' =~ /\A[\0-\x{ff}]\z/ui       # Doesn't match
479  'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui   # No match
480  'ss' =~ /\A[\xDF-\xDF]\z/ui   # Matches on ASCII platforms, since
481                                # \xDF is LATIN SMALL LETTER SHARP S,
482                                # and the range is just a single
483                                # element
484
485 Note that it isn't a good idea to specify these types of ranges anyway.
486
487 =item *
488
489 Some names known to C<\N{...}> refer to a sequence of multiple characters,
490 instead of the usual single character.  When one of these is included in
491 the class, the entire sequence is matched.  For example,
492
493   "\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}"
494                               =~ / ^ [\N{TAMIL SYLLABLE KAU}]  $ /x;
495
496 matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence
497 consisting of the two characters matched against.  Like the other
498 instance where a bracketed class can match multiple characters, and for
499 similar reasons, the class must not be inverted, and the named sequence
500 may not appear in a range, even one where it is both endpoints.  If
501 these happen, it is a fatal error if the character class is within an
502 extended L<C<(?[...])>|/Extended Bracketed Character Classes>
503 class; and only the first code point is used (with
504 a C<regexp>-type warning raised) otherwise.
505
506 =back
507
508 =head3 Special Characters Inside a Bracketed Character Class
509
510 Most characters that are meta characters in regular expressions (that
511 is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
512 their special meaning and can be used inside a character class without
513 the need to escape them. For instance, C<[()]> matches either an opening
514 parenthesis, or a closing parenthesis, and the parens inside the character
515 class don't group or capture.
516
517 Characters that may carry a special meaning inside a character class are:
518 C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
519 escaped with a backslash, although this is sometimes not needed, in which
520 case the backslash may be omitted.
521
522 The sequence C<\b> is special inside a bracketed character class. While
523 outside the character class, C<\b> is an assertion indicating a point
524 that does not have either two word characters or two non-word characters
525 on either side, inside a bracketed character class, C<\b> matches a
526 backspace character.
527
528 The sequences
529 C<\a>,
530 C<\c>,
531 C<\e>,
532 C<\f>,
533 C<\n>,
534 C<\N{I<NAME>}>,
535 C<\N{U+I<hex char>}>,
536 C<\r>,
537 C<\t>,
538 and
539 C<\x>
540 are also special and have the same meanings as they do outside a
541 bracketed character class.
542
543 Also, a backslash followed by two or three octal digits is considered an octal
544 number.
545
546 A C<[> is not special inside a character class, unless it's the start of a
547 POSIX character class (see L</POSIX Character Classes> below). It normally does
548 not need escaping.
549
550 A C<]> is normally either the end of a POSIX character class (see
551 L</POSIX Character Classes> below), or it signals the end of the bracketed
552 character class.  If you want to include a C<]> in the set of characters, you
553 must generally escape it.
554
555 However, if the C<]> is the I<first> (or the second if the first
556 character is a caret) character of a bracketed character class, it
557 does not denote the end of the class (as you cannot have an empty class)
558 and is considered part of the set of characters that can be matched without
559 escaping.
560
561 Examples:
562
563  "+"   =~ /[+?*]/     #  Match, "+" in a character class is not special.
564  "\cH" =~ /[\b]/      #  Match, \b inside in a character class
565                       #  is equivalent to a backspace.
566  "]"   =~ /[][]/      #  Match, as the character class contains
567                       #  both [ and ].
568  "[]"  =~ /[[]]/      #  Match, the pattern contains a character class
569                       #  containing just [, and the character class is
570                       #  followed by a ].
571
572 =head3 Character Ranges
573
574 It is not uncommon to want to match a range of characters. Luckily, instead
575 of listing all characters in the range, one may use the hyphen (C<->).
576 If inside a bracketed character class you have two characters separated
577 by a hyphen, it's treated as if all characters between the two were in
578 the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]>
579 matches any lowercase letter from the first half of the ASCII alphabet.
580
581 Note that the two characters on either side of the hyphen are not
582 necessarily both letters or both digits. Any character is possible,
583 although not advisable.  C<['-?]> contains a range of characters, but
584 most people will not know which characters that means.  Furthermore,
585 such ranges may lead to portability problems if the code has to run on
586 a platform that uses a different character set, such as EBCDIC.
587
588 If a hyphen in a character class cannot syntactically be part of a range, for
589 instance because it is the first or the last character of the character class,
590 or if it immediately follows a range, the hyphen isn't special, and so is
591 considered a character to be matched literally.  If you want a hyphen in
592 your set of characters to be matched and its position in the class is such
593 that it could be considered part of a range, you must escape that hyphen
594 with a backslash.
595
596 Examples:
597
598  [a-z]       #  Matches a character that is a lower case ASCII letter.
599  [a-fz]      #  Matches any letter between 'a' and 'f' (inclusive) or
600              #  the letter 'z'.
601  [-z]        #  Matches either a hyphen ('-') or the letter 'z'.
602  [a-f-m]     #  Matches any letter between 'a' and 'f' (inclusive), the
603              #  hyphen ('-'), or the letter 'm'.
604  ['-?]       #  Matches any of the characters  '()*+,-./0123456789:;<=>?
605              #  (But not on an EBCDIC platform).
606  [\N{APOSTROPHE}-\N{QUESTION MARK}]
607              #  Matches any of the characters  '()*+,-./0123456789:;<=>?
608              #  even on an EBCDIC platform.
609  [\N{U+27}-\N{U+3F}] # Same. (U+27 is "'", and U+3F is "?")
610
611 As the final two examples above show, you can achieve portablity to
612 non-ASCII platforms by using the C<\N{...}> form for the range
613 endpoints.  These indicate that the specified range is to be interpreted
614 using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match
615 C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>,
616 and C<\N{U+3F}>, whatever the native code point versions for those are.
617 These are called "Unicode" ranges.  If either end is of the C<\N{...}>
618 form, the range is considered Unicode.  A C<regexp> warning is raised
619 under C<S<"use re 'strict'">> if the other endpoint is specified
620 non-portably:
621
622  [\N{U+00}-\x09]    # Warning under re 'strict'; \x09 is non-portable
623  [\N{U+00}-\t]      # No warning;
624
625 Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ...
626 C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a
627 mistake so the warning is raised (under C<re 'strict'>) for it.
628
629 Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any
630 subranges of these match what an English-only speaker would expect them
631 to match on any platform.  That is, C<[A-Z]> matches the 26 ASCII
632 uppercase letters;
633 C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10
634 digits.  Subranges, like C<[h-k]>, match correspondingly, in this case
635 just the four letters C<"h">, C<"i">, C<"j">, and C<"k">.  This is the
636 natural behavior on ASCII platforms where the code points (ordinal
637 values) for C<"h"> through C<"k"> are consecutive integers (0x68 through
638 0x6B).  But special handling to achieve this may be needed on platforms
639 with a non-ASCII native character set.  For example, on EBCDIC
640 platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is
641 0x91, and C<"k"> is 0x92.   Perl specially treats C<[h-k]> to exclude the
642 seven code points in the gap: 0x8A through 0x90.  This special handling is
643 only invoked when the range is a subrange of one of the ASCII uppercase,
644 lowercase, and digit ranges, AND each end of the range is expressed
645 either as a literal, like C<"A">, or as a named character (C<\N{...}>,
646 including the C<\N{U+...> form).
647
648 EBCDIC Examples:
649
650  [i-j]               #  Matches either "i" or "j"
651  [i-\N{LATIN SMALL LETTER J}]  # Same
652  [i-\N{U+6A}]        #  Same
653  [\N{U+69}-\N{U+6A}] #  Same
654  [\x{89}-\x{91}]     #  Matches 0x89 ("i"), 0x8A .. 0x90, 0x91 ("j")
655  [i-\x{91}]          #  Same
656  [\x{89}-j]          #  Same
657  [i-J]               #  Matches, 0x89 ("i") .. 0xC1 ("J"); special
658                      #  handling doesn't apply because range is mixed
659                      #  case
660
661 =head3 Negation
662
663 It is also possible to instead list the characters you do not want to
664 match. You can do so by using a caret (C<^>) as the first character in the
665 character class. For instance, C<[^a-z]> matches any character that is not a
666 lowercase ASCII letter, which therefore includes more than a million
667 Unicode code points.  The class is said to be "negated" or "inverted".
668
669 This syntax make the caret a special character inside a bracketed character
670 class, but only if it is the first character of the class. So if you want
671 the caret as one of the characters to match, either escape the caret or
672 else don't list it first.
673
674 In inverted bracketed character classes, Perl ignores the Unicode rules
675 that normally say that named sequence, and certain characters should
676 match a sequence of multiple characters use under caseless C</i>
677 matching.  Following those rules could lead to highly confusing
678 situations:
679
680  "ss" =~ /^[^\xDF]+$/ui;   # Matches!
681
682 This should match any sequences of characters that aren't C<\xDF> nor
683 what C<\xDF> matches under C</i>.  C<"s"> isn't C<\xDF>, but Unicode
684 says that C<"ss"> is what C<\xDF> matches under C</i>.  So which one
685 "wins"? Do you fail the match because the string has C<ss> or accept it
686 because it has an C<s> followed by another C<s>?  Perl has chosen the
687 latter.  (See note in L</Bracketed Character Classes> above.)
688
689 Examples:
690
691  "e"  =~  /[^aeiou]/   #  No match, the 'e' is listed.
692  "x"  =~  /[^aeiou]/   #  Match, as 'x' isn't a lowercase vowel.
693  "^"  =~  /[^^]/       #  No match, matches anything that isn't a caret.
694  "^"  =~  /[x^]/       #  Match, caret is not special here.
695
696 =head3 Backslash Sequences
697
698 You can put any backslash sequence character class (with the exception of
699 C<\N> and C<\R>) inside a bracketed character class, and it will act just
700 as if you had put all characters matched by the backslash sequence inside the
701 character class. For instance, C<[a-f\d]> matches any decimal digit, or any
702 of the lowercase letters between 'a' and 'f' inclusive.
703
704 C<\N> within a bracketed character class must be of the forms C<\N{I<name>}>
705 or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines,
706 for the same reason that a dot C<.> inside a bracketed character class loses
707 its special meaning: it matches nearly anything, which generally isn't what you
708 want to happen.
709
710
711 Examples:
712
713  /[\p{Thai}\d]/     # Matches a character that is either a Thai
714                     # character, or a digit.
715  /[^\p{Arabic}()]/  # Matches a character that is neither an Arabic
716                     # character, nor a parenthesis.
717
718 Backslash sequence character classes cannot form one of the endpoints
719 of a range.  Thus, you can't say:
720
721  /[\p{Thai}-\d]/     # Wrong!
722
723 =head3 POSIX Character Classes
724 X<character class> X<\p> X<\p{}>
725 X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph>
726 X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit>
727
728 POSIX character classes have the form C<[:class:]>, where I<class> is the
729 name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear
730 I<inside> bracketed character classes, and are a convenient and descriptive
731 way of listing a group of characters.
732
733 Be careful about the syntax,
734
735  # Correct:
736  $string =~ /[[:alpha:]]/
737
738  # Incorrect (will warn):
739  $string =~ /[:alpha:]/
740
741 The latter pattern would be a character class consisting of a colon,
742 and the letters C<a>, C<l>, C<p> and C<h>.
743
744 POSIX character classes can be part of a larger bracketed character class.
745 For example,
746
747  [01[:alpha:]%]
748
749 is valid and matches '0', '1', any alphabetic character, and the percent sign.
750
751 Perl recognizes the following POSIX character classes:
752
753  alpha  Any alphabetical character ("[A-Za-z]").
754  alnum  Any alphanumeric character ("[A-Za-z0-9]").
755  ascii  Any character in the ASCII character set.
756  blank  A GNU extension, equal to a space or a horizontal tab ("\t").
757  cntrl  Any control character.  See Note [2] below.
758  digit  Any decimal digit ("[0-9]"), equivalent to "\d".
759  graph  Any printable character, excluding a space.  See Note [3] below.
760  lower  Any lowercase character ("[a-z]").
761  print  Any printable character, including a space.  See Note [4] below.
762  punct  Any graphical character excluding "word" characters.  Note [5].
763  space  Any whitespace character. "\s" including the vertical tab
764         ("\cK").
765  upper  Any uppercase character ("[A-Z]").
766  word   A Perl extension ("[A-Za-z0-9_]"), equivalent to "\w".
767  xdigit Any hexadecimal digit ("[0-9a-fA-F]").
768
769 Like the L<Unicode properties|/Unicode Properties>, most of the POSIX
770 properties match the same regardless of whether case-insensitive (C</i>)
771 matching is in effect or not.  The two exceptions are C<[:upper:]> and
772 C<[:lower:]>.  Under C</i>, they each match the union of C<[:upper:]> and
773 C<[:lower:]>.
774
775 Most POSIX character classes have two Unicode-style C<\p> property
776 counterparts.  (They are not official Unicode properties, but Perl extensions
777 derived from official Unicode properties.)  The table below shows the relation
778 between POSIX character classes and these counterparts.
779
780 One counterpart, in the column labelled "ASCII-range Unicode" in
781 the table, matches only characters in the ASCII character set.
782
783 The other counterpart, in the column labelled "Full-range Unicode", matches any
784 appropriate characters in the full Unicode character set.  For example,
785 C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any
786 character in the entire Unicode character set considered alphabetic.
787 An entry in the column labelled "backslash sequence" is a (short)
788 equivalent.
789
790  [[:...:]]      ASCII-range          Full-range  backslash  Note
791                  Unicode              Unicode     sequence
792  -----------------------------------------------------
793    alpha      \p{PosixAlpha}       \p{XPosixAlpha}
794    alnum      \p{PosixAlnum}       \p{XPosixAlnum}
795    ascii      \p{ASCII}
796    blank      \p{PosixBlank}       \p{XPosixBlank}  \h      [1]
797                                    or \p{HorizSpace}        [1]
798    cntrl      \p{PosixCntrl}       \p{XPosixCntrl}          [2]
799    digit      \p{PosixDigit}       \p{XPosixDigit}  \d
800    graph      \p{PosixGraph}       \p{XPosixGraph}          [3]
801    lower      \p{PosixLower}       \p{XPosixLower}
802    print      \p{PosixPrint}       \p{XPosixPrint}          [4]
803    punct      \p{PosixPunct}       \p{XPosixPunct}          [5]
804               \p{PerlSpace}        \p{XPerlSpace}   \s      [6]
805    space      \p{PosixSpace}       \p{XPosixSpace}          [6]
806    upper      \p{PosixUpper}       \p{XPosixUpper}
807    word       \p{PosixWord}        \p{XPosixWord}   \w
808    xdigit     \p{PosixXDigit}      \p{XPosixXDigit}
809
810 =over 4
811
812 =item [1]
813
814 C<\p{Blank}> and C<\p{HorizSpace}> are synonyms.
815
816 =item [2]
817
818 Control characters don't produce output as such, but instead usually control
819 the terminal somehow: for example, newline and backspace are control characters.
820 On ASCII platforms, in the ASCII range, characters whose code points are
821 between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on
822 EBCDIC platforms, their counterparts are control characters.
823
824 =item [3]
825
826 Any character that is I<graphical>, that is, visible. This class consists
827 of all alphanumeric characters and all punctuation characters.
828
829 =item [4]
830
831 All printable characters, which is the set of all graphical characters
832 plus those whitespace characters which are not also controls.
833
834 =item [5]
835
836 C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all
837 non-controls, non-alphanumeric, non-space characters:
838 C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect,
839 it could alter the behavior of C<[[:punct:]]>).
840
841 The similarly named property, C<\p{Punct}>, matches a somewhat different
842 set in the ASCII range, namely
843 C<[-!"#%&'()*,./:;?@[\\\]_{}]>.  That is, it is missing the nine
844 characters C<[$+E<lt>=E<gt>^`|~]>.
845 This is because Unicode splits what POSIX considers to be punctuation into two
846 categories, Punctuation and Symbols.
847
848 C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what
849 C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}>
850 matches.  This is different than strictly matching according to
851 C<\p{Punct}>.  Another way to say it is that
852 if Unicode rules are in effect, C<[[:punct:]]> matches all characters
853 that Unicode considers punctuation, plus all ASCII-range characters that
854 Unicode considers symbols.
855
856 =item [6]
857
858 C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl
859 v5.18.  In earlier versions, these differ only in that in non-locale
860 matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>.
861 Same for the two ASCII-only range forms.
862
863 =back
864
865 There are various other synonyms that can be used besides the names
866 listed in the table.  For example, C<\p{PosixAlpha}> can be written as
867 C<\p{Alpha}>.  All are listed in
868 L<perluniprops/Properties accessible through \p{} and \P{}>.
869
870 Both the C<\p> counterparts always assume Unicode rules are in effect.
871 On ASCII platforms, this means they assume that the code points from 128
872 to 255 are Latin-1, and that means that using them under locale rules is
873 unwise unless the locale is guaranteed to be Latin-1 or UTF-8.  In contrast, the
874 POSIX character classes are useful under locale rules.  They are
875 affected by the actual rules in effect, as follows:
876
877 =over
878
879 =item If the C</a> modifier, is in effect ...
880
881 Each of the POSIX classes matches exactly the same as their ASCII-range
882 counterparts.
883
884 =item otherwise ...
885
886 =over
887
888 =item For code points above 255 ...
889
890 The POSIX class matches the same as its Full-range counterpart.
891
892 =item For code points below 256 ...
893
894 =over
895
896 =item if locale rules are in effect ...
897
898 The POSIX class matches according to the locale, except:
899
900 =over
901
902 =item C<word>
903
904 also includes the platform's native underscore character, no matter what
905 the locale is.
906
907 =item C<ascii>
908
909 on platforms that don't have the POSIX C<ascii> extension, this matches
910 just the platform's native ASCII-range characters.
911
912 =item C<blank>
913
914 on platforms that don't have the POSIX C<blank> extension, this matches
915 just the platform's native tab and space characters.
916
917 =back
918
919 =item if Unicode rules are in effect ...
920
921 The POSIX class matches the same as the Full-range counterpart.
922
923 =item otherwise ...
924
925 The POSIX class matches the same as the ASCII range counterpart.
926
927 =back
928
929 =back
930
931 =back
932
933 Which rules apply are determined as described in
934 L<perlre/Which character set modifier is in effect?>.
935
936 It is proposed to change this behavior in a future release of Perl so that
937 whether or not Unicode rules are in effect would not change the
938 behavior:  Outside of locale, the POSIX classes
939 would behave like their ASCII-range counterparts.  If you wish to
940 comment on this proposal, send email to C<perl5-porters@perl.org>.
941
942 =head4 Negation of POSIX character classes
943 X<character class, negation>
944
945 A Perl extension to the POSIX character class is the ability to
946 negate it. This is done by prefixing the class name with a caret (C<^>).
947 Some examples:
948
949      POSIX         ASCII-range     Full-range  backslash
950                     Unicode         Unicode    sequence
951  -----------------------------------------------------
952  [[:^digit:]]   \P{PosixDigit}  \P{XPosixDigit}   \D
953  [[:^space:]]   \P{PosixSpace}  \P{XPosixSpace}
954                 \P{PerlSpace}   \P{XPerlSpace}    \S
955  [[:^word:]]    \P{PerlWord}    \P{XPosixWord}    \W
956
957 The backslash sequence can mean either ASCII- or Full-range Unicode,
958 depending on various factors as described in L<perlre/Which character set modifier is in effect?>.
959
960 =head4 [= =] and [. .]
961
962 Perl recognizes the POSIX character classes C<[=class=]> and
963 C<[.class.]>, but does not (yet?) support them.  Any attempt to use
964 either construct raises an exception.
965
966 =head4 Examples
967
968  /[[:digit:]]/            # Matches a character that is a digit.
969  /[01[:lower:]]/          # Matches a character that is either a
970                           # lowercase letter, or '0' or '1'.
971  /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
972                           # except the letters 'a' to 'f' and 'A' to
973                           # 'F'.  This is because the main character
974                           # class is composed of two POSIX character
975                           # classes that are ORed together, one that
976                           # matches any digit, and the other that
977                           # matches anything that isn't a hex digit.
978                           # The OR adds the digits, leaving only the
979                           # letters 'a' to 'f' and 'A' to 'F' excluded.
980
981 =head3 Extended Bracketed Character Classes
982 X<character class>
983 X<set operations>
984
985 This is a fancy bracketed character class that can be used for more
986 readable and less error-prone classes, and to perform set operations,
987 such as intersection. An example is
988
989  /(?[ \p{Thai} & \p{Digit} ])/
990
991 This will match all the digit characters that are in the Thai script.
992
993 This is an experimental feature available starting in 5.18, and is
994 subject to change as we gain field experience with it.  Any attempt to
995 use it will raise a warning, unless disabled via
996
997  no warnings "experimental::regex_sets";
998
999 Comments on this feature are welcome; send email to
1000 C<perl5-porters@perl.org>.
1001
1002 We can extend the example above:
1003
1004  /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/
1005
1006 This matches digits that are in either the Thai or Laotian scripts.
1007
1008 Notice the white space in these examples.  This construct always has
1009 the C<E<sol>x> modifier turned on within it.
1010
1011 The available binary operators are:
1012
1013  &    intersection
1014  +    union
1015  |    another name for '+', hence means union
1016  -    subtraction (the result matches the set consisting of those
1017       code points matched by the first operand, excluding any that
1018       are also matched by the second operand)
1019  ^    symmetric difference (the union minus the intersection).  This
1020       is like an exclusive or, in that the result is the set of code
1021       points that are matched by either, but not both, of the
1022       operands.
1023
1024 There is one unary operator:
1025
1026  !    complement
1027
1028 All the binary operators left associate; C<"&"> is higher precedence
1029 than the others, which all have equal precedence.  The unary operator
1030 right associates, and has highest precedence.  Thus this follows the
1031 normal Perl precedence rules for logical operators.  Use parentheses to
1032 override the default precedence and associativity.
1033
1034 The main restriction is that everything is a metacharacter.  Thus,
1035 you cannot refer to single characters by doing something like this:
1036
1037  /(?[ a + b ])/ # Syntax error!
1038
1039 The easiest way to specify an individual typable character is to enclose
1040 it in brackets:
1041
1042  /(?[ [a] + [b] ])/
1043
1044 (This is the same thing as C<[ab]>.)  You could also have said the
1045 equivalent:
1046
1047  /(?[[ a b ]])/
1048
1049 (You can, of course, specify single characters by using, C<\x{...}>,
1050 C<\N{...}>, etc.)
1051
1052 This last example shows the use of this construct to specify an ordinary
1053 bracketed character class without additional set operations.  Note the
1054 white space within it; C<E<sol>x> is turned on even within bracketed
1055 character classes, except you can't have comments inside them.  Hence,
1056
1057  (?[ [#] ])
1058
1059 matches the literal character "#".  To specify a literal white space character,
1060 you can escape it with a backslash, like:
1061
1062  /(?[ [ a e i o u \  ] ])/
1063
1064 This matches the English vowels plus the SPACE character.
1065 All the other escapes accepted by normal bracketed character classes are
1066 accepted here as well; but unrecognized escapes that generate warnings
1067 in normal classes are fatal errors here.
1068
1069 All warnings from these class elements are fatal, as well as some
1070 practices that don't currently warn.  For example you cannot say
1071
1072  /(?[ [ \xF ] ])/     # Syntax error!
1073
1074 You have to have two hex digits after a braceless C<\x> (use a leading
1075 zero to make two).  These restrictions are to lower the incidence of
1076 typos causing the class to not match what you thought it would.
1077
1078 If a regular bracketed character class contains a C<\p{}> or C<\P{}> and
1079 is matched against a non-Unicode code point, a warning may be
1080 raised, as the result is not Unicode-defined.  No such warning will come
1081 when using this extended form.
1082
1083 The final difference between regular bracketed character classes and
1084 these, is that it is not possible to get these to match a
1085 multi-character fold.  Thus,
1086
1087  /(?[ [\xDF] ])/iu
1088
1089 does not match the string C<ss>.
1090
1091 You don't have to enclose POSIX class names inside double brackets,
1092 hence both of the following work:
1093
1094  /(?[ [:word:] - [:lower:] ])/
1095  /(?[ [[:word:]] - [[:lower:]] ])/
1096
1097 Any contained POSIX character classes, including things like C<\w> and C<\D>
1098 respect the C<E<sol>a> (and C<E<sol>aa>) modifiers.
1099
1100 C<< (?[ ]) >> is a regex-compile-time construct.  Any attempt to use
1101 something which isn't knowable at the time the containing regular
1102 expression is compiled is a fatal error.  In practice, this means
1103 just three limitations:
1104
1105 =over 4
1106
1107 =item 1
1108
1109 When compiled within the scope of C<use locale> (or the C<E<sol>l> regex
1110 modifier), this construct assumes that the execution-time locale will be
1111 a UTF-8 one, and the generated pattern always uses Unicode rules.  What
1112 gets matched or not thus isn't dependent on the actual runtime locale, so
1113 tainting is not enabled.  But a C<locale> category warning is raised
1114 if the runtime locale turns out to not be UTF-8.
1115
1116 =item 2
1117
1118 Any
1119 L<user-defined property|perlunicode/"User-Defined Character Properties">
1120 used must be already defined by the time the regular expression is
1121 compiled (but note that this construct can be used instead of such
1122 properties).
1123
1124 =item 3
1125
1126 A regular expression that otherwise would compile
1127 using C<E<sol>d> rules, and which uses this construct will instead
1128 use C<E<sol>u>.  Thus this construct tells Perl that you don't want
1129 C<E<sol>d> rules for the entire regular expression containing it.
1130
1131 =back
1132
1133 Note that skipping white space applies only to the interior of this
1134 construct.  There must not be any space between any of the characters
1135 that form the initial C<(?[>.  Nor may there be space between the
1136 closing C<])> characters.
1137
1138 Just as in all regular expressions, the pattern can be built up by
1139 including variables that are interpolated at regex compilation time.
1140 Care must be taken to ensure that you are getting what you expect.  For
1141 example:
1142
1143  my $thai_or_lao = '\p{Thai} + \p{Lao}';
1144  ...
1145  qr/(?[ \p{Digit} & $thai_or_lao ])/;
1146
1147 compiles to
1148
1149  qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
1150
1151 But this does not have the effect that someone reading the code would
1152 likely expect, as the intersection applies just to C<\p{Thai}>,
1153 excluding the Laotian.  Pitfalls like this can be avoided by
1154 parenthesizing the component pieces:
1155
1156  my $thai_or_lao = '( \p{Thai} + \p{Lao} )';
1157
1158 But any modifiers will still apply to all the components:
1159
1160  my $lower = '\p{Lower} + \p{Digit}';
1161  qr/(?[ \p{Greek} & $lower ])/i;
1162
1163 matches upper case things.  You can avoid surprises by making the
1164 components into instances of this construct by compiling them:
1165
1166  my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
1167  my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
1168
1169 When these are embedded in another pattern, what they match does not
1170 change, regardless of parenthesization or what modifiers are in effect
1171 in that outer pattern.
1172
1173 Due to the way that Perl parses things, your parentheses and brackets
1174 may need to be balanced, even including comments.  If you run into any
1175 examples, please send them to C<perlbug@perl.org>, so that we can have a
1176 concrete example for this man page.
1177
1178 We may change it so that things that remain legal uses in normal bracketed
1179 character classes might become illegal within this experimental
1180 construct.  One proposal, for example, is to forbid adjacent uses of the
1181 same character, as in C<(?[ [aa] ])>.  The motivation for such a change
1182 is that this usage is likely a typo, as the second "a" adds nothing.