Debian Codegraph @

upstream/fedora-44/man1/perlrecharclass.1

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