perlrecharclass > 5.18.1 との差分

perlrecharclass 5.18.1 と 5.40.0 の差分

11
2=encoding euc-jp
2=encoding utf8
33
44=head1 NAME
55X<character class>
66
77=begin original
88
99perlrecharclass - Perl Regular Expression Character Classes
1010
1111=end original
1212
1313perlrecharclass - Perl 正規表現文字クラス
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The top level documentation about Perl regular expressions
2020is found in L<perlre>.
2121
2222=end original
2323
2424Perl 正規表現に関する最上位文書は L<perlre> です。
2525
2626=begin original
2727
2828This manual page discusses the syntax and use of character
2929classes in Perl regular expressions.
3030
3131=end original
3232
3333このマニュアルページは Perl 正規表現の文字クラスの文法と使用法について
3434議論します。
3535
3636=begin original
3737
3838A character class is a way of denoting a set of characters
3939in such a way that one character of the set is matched.
4040It's important to remember that: matching a character class
4141consumes exactly one character in the source string. (The source
4242string is the string the regular expression is matched against.)
4343
4444=end original
4545
4646文字クラスは、集合の中の一文字がマッチングするというような方法で、
4747文字の集合を指定するための方法です。
4848次のことを覚えておくことは重要です: 文字集合はソース文字列の中から正確に
4949一文字だけを消費します。
5050(ソース文字列とは正規表現がマッチングしようとしている文字列です。)
5151
5252=begin original
5353
5454There are three types of character classes in Perl regular
5555expressions: the dot, backslash sequences, and the form enclosed in square
5656brackets. Keep in mind, though, that often the term "character class" is used
5757to mean just the bracketed form. Certainly, most Perl documentation does that.
5858
5959=end original
6060
6161Perl 正規表現には 3 種類の文字クラスがあります: ドット、
6262逆スラッシュシーケンス、大かっこで囲まれた形式です。
6363しかし、「文字クラス」という用語はしばしば大かっこ形式だけを意味するために
6464使われることに注意してください。
6565確かに、ほとんどの Perl 文書ではそうなっています。
6666
6767=head2 The dot
6868
6969(ドット)
7070
7171=begin original
7272
7373The dot (or period), C<.> is probably the most used, and certainly
7474the most well-known character class. By default, a dot matches any
7575character, except for the newline. That default can be changed to
76add matching the newline by using the I<single line> modifier: either
76add matching the newline by using the I<single line> modifier:
7777for the entire regular expression with the C</s> modifier, or
78locally with C<(?s)>. (The C<\N> backslash sequence, described
78locally with C<(?s)> (and even globally within the scope of
79L<C<use re '/s'>|re/'E<sol>flags' mode>). (The C<L</\N>> backslash
80sequence, described
7981below, matches any character except newline without regard to the
8082I<single line> modifier.)
8183
8284=end original
8385
8486ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に
8587もっともよく知られている文字クラスです。
8688デフォルトでは、ドットは改行を除く任意の文字にマッチングします。
8789このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
8890変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには
89C<(?s)> を使います
91C<(?s)> を使います
90(後述する C<\N> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
92(そしてグローバルに L<C<use re '/s'>|re/'E<sol>flags' mode> の
93スコープ内の場合でもそうです)。
94(後述する C<L</\N>> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
9195関わりなく改行以外の任意の文字にマッチングします。)
9296
9397=begin original
9498
9599Here are some examples:
96100
97101=end original
98102
99103以下は例です:
100104
101105=begin original
102106
103107 "a" =~ /./ # Match
104108 "." =~ /./ # Match
105109 "" =~ /./ # No match (dot has to match a character)
106110 "\n" =~ /./ # No match (dot does not match a newline)
107111 "\n" =~ /./s # Match (global 'single line' modifier)
108112 "\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
109113 "ab" =~ /^.$/ # No match (dot matches one character)
110114
111115=end original
112116
113117 "a" =~ /./ # マッチングする
114118 "." =~ /./ # マッチングする
115119 "" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
116120 "\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
117121 "\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
118122 "\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
119123 "ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
120124
121125=head2 Backslash sequences
122126X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
123127X<\N> X<\v> X<\V> X<\h> X<\H>
124128X<word> X<whitespace>
125129
126130(逆スラッシュシーケンス)
127131
128132=begin original
129133
130134A backslash sequence is a sequence of characters, the first one of which is a
131135backslash. Perl ascribes special meaning to many such sequences, and some of
132136these are character classes. That is, they match a single character each,
133137provided that the character belongs to the specific set of characters defined
134138by the sequence.
135139
136140=end original
137141
138142逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。
139143Perl はそのような並びの多くに特別な意味を持たせていて、
140144その一部は文字クラスです。
141145つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に
142146帰属する一文字にマッチングします。
143147
144148=begin original
145149
146150Here's a list of the backslash sequences that are character classes. They
147151are discussed in more detail below. (For the backslash sequences that aren't
148152character classes, see L<perlrebackslash>.)
149153
150154=end original
151155
152156以下は文字クラスの逆スラッシュシーケンスの一覧です。
153157以下でさらに詳細に議論します。
154158(文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を
155159参照してください。)
156160
157161=begin original
158162
159163 \d Match a decimal digit character.
160164 \D Match a non-decimal-digit character.
161165 \w Match a "word" character.
162166 \W Match a non-"word" character.
163167 \s Match a whitespace character.
164168 \S Match a non-whitespace character.
165169 \h Match a horizontal whitespace character.
166170 \H Match a character that isn't horizontal whitespace.
167171 \v Match a vertical whitespace character.
168172 \V Match a character that isn't vertical whitespace.
169173 \N Match a character that isn't a newline.
170174 \pP, \p{Prop} Match a character that has the given Unicode property.
171175 \PP, \P{Prop} Match a character that doesn't have the Unicode property
172176
173177=end original
174178
175179 \d 10 進数字にマッチング。
176180 \D 非 10 進数字にマッチング。
177181 \w 「単語」文字にマッチング。
178182 \W 非「単語」文字にマッチング。
179183 \s 空白文字にマッチング。
180184 \S 非空白文字にマッチング。
181185 \h 水平空白文字にマッチング。
182186 \H 水平空白でない文字にマッチング。
183187 \v 垂直空白文字にマッチング。
184188 \V 垂直空白でない文字にマッチング。
185189 \N 改行以外の文字にマッチング。
186190 \pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
187191 \PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
188192
189193=head3 \N
190194
191195=begin original
192196
193197C<\N>, available starting in v5.12, like the dot, matches any
194198character that is not a newline. The difference is that C<\N> is not influenced
195199by the I<single line> regular expression modifier (see L</The dot> above). Note
196200that the form C<\N{...}> may mean something completely different. When the
197201C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
198202character that many times. For example, C<\N{3}> means to match 3
199203non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}>
200204is not a legal quantifier, it is presumed to be a named character. See
201205L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and
202206C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
203207names are respectively C<COLON>, C<4F>, and C<F4>.
204208
205209=end original
206210
207211v5.12 から利用可能な C<\N> は、ドットのように、
208212改行以外の任意の文字にマッチングします。
209213違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです
210214(上述の L</The dot> 参照)。
211215C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに
212216注意してください。
213217C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の
214218非改行文字にマッチングします。
215219例えば、C<\N{3}> は三つの非改行にマッチングします;
216220C<\N{5,}> は五つ以上の非改行にマッチングします。
217221しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と
218222推定されます。
219223これについては L<charnames> を参照してください。
220224例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な
221225量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の
222226文字を探そうとします。
223227
224228=head3 Digits
225229
226230(数字)
227231
228232=begin original
229233
230234C<\d> matches a single character considered to be a decimal I<digit>.
231235If the C</a> regular expression modifier is in effect, it matches [0-9].
232236Otherwise, it
233237matches anything that is matched by C<\p{Digit}>, which includes [0-9].
234238(An unlikely possible exception is that under locale matching rules, the
235current locale might not have [0-9] matched by C<\d>, and/or might match
239current locale might not have C<[0-9]> matched by C<\d>, and/or might match
236other characters whose code point is less than 256. Such a locale
240other characters whose code point is less than 256. The only such locale
237definition would be in violation of the C language standard, but Perl
241definitions that are legal would be to match C<[0-9]> plus another set of
238doesn't currently assume anything in regard to this.)
24210 consecutive digit characters; anything else would be in violation of
243the C language standard, but Perl doesn't currently assume anything in
244regard to this.)
239245
240246=end original
241247
242248C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。
243249C</a> 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。
244さもなければ、これは [0-9] を含む、C<\p{Digit}> にマッチングするものに
250さもなければ、これは C<[0-9]> を含む、C<\p{Digit}> にマッチングするものに
245251マッチングします。
246252(ありそうもない例外はロケールマッチングの下で、現在のロケールが
247253C<\d> にマッチングする [0-9] がないか、
248254符号位置が 256 未満の他の文字にマッチングすることです。
249このようなロケール定義は C 言語標準違反しいますが、
255唯一正当なロケール定義はC<[0-9]>加えもう一つの 10 の連続した
256数字の集合にマッチングするもので、
257それ以外は C 言語標準に違反していますが、
250258Perl は今のところこれに関して何も仮定しません。)
251259
252260=begin original
253261
254262What this means is that unless the C</a> modifier is in effect C<\d> not
255263only matches the digits '0' - '9', but also Arabic, Devanagari, and
256264digits from other languages. This may cause some confusion, and some
257265security issues.
258266
259267=end original
260268
261269これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字
262270'0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の
263271数字もマッチングします。
264272これは混乱やセキュリティ問題を引き起こすことがあります。
265273
266274=begin original
267275
268276Some digits that C<\d> matches look like some of the [0-9] ones, but
269277have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks
270very much like an ASCII DIGIT EIGHT (U+0038). An application that
278very much like an ASCII DIGIT EIGHT (U+0038), and LEPCHA DIGIT SIX
279(U+1C46) looks very much like an ASCII DIGIT FIVE (U+0035). An
280application that
271281is expecting only the ASCII digits might be misled, or if the match is
272282C<\d+>, the matched string might contain a mixture of digits from
273283different writing systems that look like they signify a number different
274284than they actually do. L<Unicode::UCD/num()> can
275285be used to safely
276286calculate the value, returning C<undef> if the input string contains
277such a mixture.
287such a mixture. Otherwise, for example, a displayed price might be
288deliberately different than it appears.
278289
279290=end original
280291
281292C<\d> にマッチングする数字には、[0-9] のように見えるけれども、
282293異なる値を持つものもあります。
283例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038)
294例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038)
295とてもよく似ていて、
296LEPCHA DIGIT SIX (U+1C46) は ASCII DIGIT FIVE (U+0035) に
284297とてもよく似ています。
285298ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、
286299マッチングが C<\d+> の場合、
287300マッチングした文字列は、実際と異なる値を示しているように見える、
288301異なった書記体系からの数字が混ざったものかもしれません。
289302L<Unicode::UCD/num()> は値を安全に計算するのに使えます;
290303入力文字列がこのような混合を含んでいる場合は C<undef> を返します。
304さもなければ、例えば、表示された価格は見た目と意図的に違うものに
305なるかもしれません。
291306
292307=begin original
293308
294309What C<\p{Digit}> means (and hence C<\d> except under the C</a>
295310modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
296311C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this
297312is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
298313But Unicode also has a different property with a similar name,
299314C<\p{Numeric_Type=Digit}>, which matches a completely different set of
300315characters. These characters are things such as C<CIRCLED DIGIT ONE>
301316or subscripts, or are from writing systems that lack all ten digits.
302317
303318=end original
304319
305320C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、
306321C<\p{General_Category=Decimal_Number}>、または同義語として
307322C<\p{General_Category=Digit}> です。
308323Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に
309324マッチングする文字集合と同じです。
310325ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ
311326別の特性もあります; これは完全に異なる文字集合とマッチングします。
312327これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、
31332810 の数字すべてが揃っていない書記体系からのものです。
314329
315330=begin original
316331
317332The design intent is for C<\d> to exactly match the set of characters
318333that can safely be used with "normal" big-endian positional decimal
319334syntax, where, for example 123 means one 'hundred', plus two 'tens',
320335plus three 'ones'. This positional notation does not necessarily apply
321336to characters that match the other type of "digit",
322337C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
323338
324339=end original
325340
326341設計意図は、C<\d> が「通常の」ビッグエンディアンの
327342位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を
328343加えたものを意味する) で安全に使用できる文字集合と
329正確にマッチングするようにすることです;
344正確にマッチングするようにすることです
330345この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に
331346マッチングする文字には必ずしも適用されないため、
332347C<\d> はこれらの文字にマッチングしません。
333348
334349=begin original
335350
336351The Tamil digits (U+0BE6 - U+0BEF) can also legally be
337352used in old-style Tamil numbers in which they would appear no more than
338353one in a row, separated by characters that mean "times 10", "times 100",
339etc. (See L<http://www.unicode.org/notes/tn21>.)
354etc. (See L<https://www.unicode.org/notes/tn21>.)
340355
341356=end original
342357
343358タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の
344359数字でも合法的に使用することができます;
345360この数字は、「×10」や「×100」などを意味する文字で区切られて、
3463611 回に一度にしか現れません。
347(L<http://www.unicode.org/notes/tn21>を参照してください)
362(L<https://www.unicode.org/notes/tn21>を参照してください。)
348363
349364=begin original
350365
351366Any character not matched by C<\d> is matched by C<\D>.
352367
353368=end original
354369
355370C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。
356371
357372=head3 Word characters
358373
359374(単語文字)
360375
361376=begin original
362377
363378A C<\w> matches a single alphanumeric character (an alphabetic character, or a
364379decimal digit); or a connecting punctuation character, such as an
365380underscore ("_"); or a "mark" character (like some sort of accent) that
366381attaches to one of those. It does not match a whole word. To match a
367382whole word, use C<\w+>. This isn't the same thing as matching an
368383English word, but in the ASCII range it is the same as a string of
369384Perl-identifier characters.
370385
371386=end original
372387
373388C<\w> は単語全体ではなく、単一の英数字(つまり英字または数字)または
374389下線(C<_>) のような接続句読点
375390またはこれらの一つに付いている(ある種のアクセントのような)「マーク」文字に
376391マッチングします。
377392これは単語全体にはマッチングしません。
378393単語全体にマッチングするには、C<\w+> を使ってください。
379394これは英語の単語にマッチングするのと同じことではありませんが、
380395ASCII の範囲では、Perl の識別子文字の文字列と同じです。
381396
382397=over
383398
384399=item If the C</a> modifier is in effect ...
385400
386401(C</a> 修飾子が有効なら ...)
387402
388403=begin original
389404
390405C<\w> matches the 63 characters [a-zA-Z0-9_].
391406
392407=end original
393408
394409C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。
395410
396411=item otherwise ...
397412
398413(さもなければ ...)
399414
400415=over
401416
402417=item For code points above 255 ...
403418
404419(256 以上の符号位置では ...)
405420
406421=begin original
407422
408423C<\w> matches the same as C<\p{Word}> matches in this range. That is,
409424it matches Thai letters, Greek letters, etc. This includes connector
410425punctuation (like the underscore) which connect two words together, or
411426diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
412427are generally used to add auxiliary markings to letters.
413428
414429=end original
415430
416431C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに
417432マッチングします。
418433つまり、タイ文字、ギリシャ文字などです。
419434これには(下線のような)二つの単語を繋ぐ接続句読点、
420435C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために
421436使われる修飾字のようなダイアクリティカルマークが含まれます。
422437
423438=item For code points below 256 ...
424439
425440(255 以下の符号位置では ...)
426441
427442=over
428443
429444=item if locale rules are in effect ...
430445
431446(ロケール規則が有効なら ...)
432447
433448=begin original
434449
435450C<\w> matches the platform's native underscore character plus whatever
436451the locale considers to be alphanumeric.
437452
438453=end original
439454
440455C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と
441456考えるものにマッチングします。
442457
443=item if Unicode rules are in effect ...
458=item if, instead, Unicode rules are in effect ...
444459
445(Unicode 規則が有効なら ...)
460(そうではなく、Unicode 規則が有効なら ...)
446461
447462=begin original
448463
449464C<\w> matches exactly what C<\p{Word}> matches.
450465
451466=end original
452467
453468C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。
454469
455470=item otherwise ...
456471
457472(さもなければ ...)
458473
459474=begin original
460475
461476C<\w> matches [a-zA-Z0-9_].
462477
463478=end original
464479
465480C<\w> は [a-zA-Z0-9_] にマッチングします。
466481
467482=back
468483
469484=back
470485
471486=back
472487
473488=begin original
474489
475490Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
476491
477492=end original
478493
479494どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
480495記述されている方法で決定されます。
481496
482497=begin original
483498
484499There are a number of security issues with the full Unicode list of word
485characters. See L<http://unicode.org/reports/tr36>.
500characters. See L<https://unicode.org/reports/tr36>.
486501
487502=end original
488503
489504完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。
490L<http://unicode.org/reports/tr36> を参照してください。
505L<https://unicode.org/reports/tr36> を参照してください。
491506
492507=begin original
493508
494509Also, for a somewhat finer-grained set of characters that are in programming
495510language identifiers beyond the ASCII range, you may wish to instead use the
496511more customized L</Unicode Properties>, C<\p{ID_Start}>,
497512C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See
498513L<http://unicode.org/reports/tr31>.
499514
500515=end original
501516
502517また、ASCII の範囲を超えたプログラミング言語識別子のための
503518より高精度の文字集合のためには、代わりによりカスタマイズされた
504519L<Unicode 特性|/Unicode Properties>である
505520 C<\p{ID_Start}>,
506521C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を
507522使った方がよいでしょう。
508523L<http://unicode.org/reports/tr31> を参照してください。
509524
510525=begin original
511526
512527Any character not matched by C<\w> is matched by C<\W>.
513528
514529=end original
515530
516531C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。
517532
518533=head3 Whitespace
519534
520535(空白)
521536
522537=begin original
523538
524539C<\s> matches any single character considered whitespace.
525540
526541=end original
527542
528543C<\s> は空白と考えられる単一の文字にマッチングします。
529544
530545=over
531546
532547=item If the C</a> modifier is in effect ...
533548
534549(C</a> 修飾子が有効なら ...)
535550
536551=begin original
537552
538553In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that
539554is, the horizontal tab,
540555the newline, the form feed, the carriage return, and the space.
541Starting in Perl v5.18, experimentally, it also matches the vertical tab, C<\cK>.
556Starting in Perl v5.18, it also matches the vertical tab, C<\cK>.
542557See note C<[1]> below for a discussion of this.
543558
544559=end original
545560
546561全ての Perl バージョンで、C<\s> は [\t\n\f\r ] の 5 文字にマッチングします;
547562つまり、水平タブ、改行、改頁、復帰、スペースです。
548Perl 5.18 から、実験的に、垂直タブ C<\cK> にもマッチングします。
563Perl 5.18 から、垂直タブ C<\cK> にもマッチングします。
549564ここでの議論については後述する C<[1]> を参照してください。
550565
551566=item otherwise ...
552567
553568(さもなければ ...)
554569
555570=over
556571
557572=item For code points above 255 ...
558573
559574(256 以上の符号位置では ...)
560575
561576=begin original
562577
563578C<\s> matches exactly the code points above 255 shown with an "s" column
564579in the table below.
565580
566581=end original
567582
568583C<\s> は、後述する表の "s" の列で示されている、
569584255 を超える符号位置に正確にマッチングします。
570585
571586=item For code points below 256 ...
572587
573588(255 以下の符号位置では ...)
574589
575590=over
576591
577592=item if locale rules are in effect ...
578593
579594(ロケール規則が有効なら ...)
580595
581596=begin original
582597
583598C<\s> matches whatever the locale considers to be whitespace.
584599
585600=end original
586601
587602C<\s> はロケールが空白だと考えるものにマッチングします。
588603
589=item if Unicode rules are in effect ...
604=item if, instead, Unicode rules are in effect ...
590605
591(Unicode 規則が有効なら ...)
606(そうではなく、Unicode 規則が有効なら ...)
592607
593608=begin original
594609
595610C<\s> matches exactly the characters shown with an "s" column in the
596611table below.
597612
598613=end original
599614
600615C<\s> は正確に以下の表で "s" の列にある文字にマッチングします。
601616
602617=item otherwise ...
603618
604619(さもなければ ...)
605620
606621=begin original
607622
608C<\s> matches [\t\n\f\r\cK ] and, starting, experimentally in Perl
623C<\s> matches [\t\n\f\r ] and, starting in Perl
609624v5.18, the vertical tab, C<\cK>.
610625(See note C<[1]> below for a discussion of this.)
611626Note that this list doesn't include the non-breaking space.
612627
613628=end original
614629
615C<\s> は [\t\n\f\r\cK ] にマッチングし、Perl v5.18 から実験的に
630C<\s> は [\t\n\f\r ] にマッチングし、Perl v5.18 から、
616631垂直タブ C<\cK> にもマッチングします。
617632(これの議論については後述する C<[1]> を参照してください。)
618633この一覧にはノーブレークスペースが含まれていないことに注意してください。
619634
620635=back
621636
622637=back
623638
624639=back
625640
626641=begin original
627642
628643Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
629644
630645=end original
631646
632647どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
633648記述されている方法で決定されます。
634649
635650=begin original
636651
637652Any character not matched by C<\s> is matched by C<\S>.
638653
639654=end original
640655
641656C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。
642657
643658=begin original
644659
645660C<\h> matches any character considered horizontal whitespace;
646661this includes the platform's space and tab characters and several others
647662listed in the table below. C<\H> matches any character
648663not considered horizontal whitespace. They use the platform's native
649664character set, and do not consider any locale that may otherwise be in
650665use.
651666
652667=end original
653668
654669C<\h> は水平空白と考えられる任意の文字にマッチングします; これは
655670プラットフォームのスペースとタブ文字および以下の表に上げられている
656671いくつかのその他の文字です。
657672C<\H> は水平空白と考えられない文字にマッチングします。
658673これらはプラットフォームのネイティブな文字集合を使い、
659674他の場所では有効なロケールを考慮しません。
660675
661676=begin original
662677
663678C<\v> matches any character considered vertical whitespace;
664679this includes the platform's carriage return and line feed characters (newline)
665680plus several other characters, all listed in the table below.
666681C<\V> matches any character not considered vertical whitespace.
667682They use the platform's native character set, and do not consider any
668683locale that may otherwise be in use.
669684
670685=end original
671686
672687C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは
673688プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です;
674689全ては以下の表に挙げられています。
675690C<\V> は垂直空白と考えられない任意の文字にマッチングします。
676691これらはプラットフォームのネイティブな文字集合を使い、
677692他の場所では有効なロケールを考慮しません。
678693
679694=begin original
680695
681696C<\R> matches anything that can be considered a newline under Unicode
682rules. It's not a character class, as it can match a multi-character
697rules. It can match a multi-character sequence. It cannot be used inside
683sequence. Therefore, it cannot be used inside a bracketed character
698a bracketed character class; use C<\v> instead (vertical whitespace).
684class; use C<\v> instead (vertical whitespace). It uses the platform's
699It uses the platform's
685700native character set, and does not consider any locale that may
686701otherwise be in use.
687702Details are discussed in L<perlrebackslash>.
688703
689704=end original
690705
691706C<\R> は Unicode の規則で改行と考えられるものにマッチングします。
692複数文字の並びにマッチングすることもあるので、これは
707複数文字の並びにマッチングすることもあります。
693文字クラスではありません。
694708従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を
695709使ってください。
696710これらはプラットフォームのネイティブな文字集合を使い、
697711他の場所では有効なロケールを考慮しません。
698712詳細は L<perlrebackslash> で議論しています。
699713
700714=begin original
701715
702716Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
703717the same characters, without regard to other factors, such as the active
704718locale or whether the source string is in UTF-8 format.
705719
706720=end original
707721
708722C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の
709723ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず
710724同じ文字にマッチングします。
711725
712726=begin original
713727
714728One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true
715729starting in Perl v5.18, but prior to that, the sole difference was that the
716730vertical tab (C<"\cK">) was not matched by C<\s>.
717731
718732=end original
719733
720734C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。
721735Perl 5.18 からはもちろん正しいです; しかしそれより前では、
722736唯一の違いは、垂直タブ (C<"\xcK">) は C<\s> にマッチングしないということです。
723737
724738=begin original
725739
726740The following table is a complete listing of characters matched by
727C<\s>, C<\h> and C<\v> as of Unicode 6.0.
741C<\s>, C<\h> and C<\v> as of Unicode 14.0.
728742
729743=end original
730744
731以下の表は Unicode 6.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
745以下の表は Unicode 14.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
732746完全な一覧です。
733747
734748=begin original
735749
736750The first column gives the Unicode code point of the character (in hex format),
737751the second column gives the (Unicode) name. The third column indicates
738752by which class(es) the character is matched (assuming no locale is in
739753effect that changes the C<\s> matching).
740754
741755=end original
742756
743757最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の)
744758名前です。
7457593 番目の列はどのクラスにマッチングするかを示しています
746760(C<\s> のマッチングを変更するようなロケールが
747761有効でないことを仮定しています)。
748762
749763 0x0009 CHARACTER TABULATION h s
750764 0x000a LINE FEED (LF) vs
751765 0x000b LINE TABULATION vs [1]
752766 0x000c FORM FEED (FF) vs
753767 0x000d CARRIAGE RETURN (CR) vs
754768 0x0020 SPACE h s
755769 0x0085 NEXT LINE (NEL) vs [2]
756770 0x00a0 NO-BREAK SPACE h s [2]
757771 0x1680 OGHAM SPACE MARK h s
758 0x180e MONGOLIAN VOWEL SEPARATOR h s
759772 0x2000 EN QUAD h s
760773 0x2001 EM QUAD h s
761774 0x2002 EN SPACE h s
762775 0x2003 EM SPACE h s
763776 0x2004 THREE-PER-EM SPACE h s
764777 0x2005 FOUR-PER-EM SPACE h s
765778 0x2006 SIX-PER-EM SPACE h s
766779 0x2007 FIGURE SPACE h s
767780 0x2008 PUNCTUATION SPACE h s
768781 0x2009 THIN SPACE h s
769782 0x200a HAIR SPACE h s
770783 0x2028 LINE SEPARATOR vs
771784 0x2029 PARAGRAPH SEPARATOR vs
772785 0x202f NARROW NO-BREAK SPACE h s
773786 0x205f MEDIUM MATHEMATICAL SPACE h s
774787 0x3000 IDEOGRAPHIC SPACE h s
775788
776789=over 4
777790
778791=item [1]
779792
780793=begin original
781794
782Prior to Perl v5.18, C<\s> did not match the vertical tab. The change
795Prior to Perl v5.18, C<\s> did not match the vertical tab.
783in v5.18 is considered an experiment, which means it could be backed out
796C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did.
784in v5.20 or v5.22 if experience indicates that it breaks too much
785existing code. If this change adversely affects you, send email to
786C<perlbug@perl.org>; if it affects you positively, email
787C<perlthanks@perl.org>. In the meantime, C<[^\S\cK]> (obscurely)
788matches what C<\s> traditionally did.
789797
790798=end original
791799
792800Perl v5.18 より前では、C<\s> は垂直タブにマッチングしませんでした。
793v5.18 での変更実験的考えられています; つまり、
801C<[^\S\cK]>(ひっそり)C<\s> が伝統的に
794これがあまりに多くの既存のコードを壊すことが分かった場合は、
795v5.20 や v5.22 で元に戻すかもしれません。
796この変更があなたに不利に働いた場合は、
797C<perlbug@perl.org> にメールしてください; あなたに有利に働いた場合は、
798C<perlthanks@perl.org> にメールしてください。
799それまでの間は、C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的に
800802マッチングしていたものにマッチングします。
801803
802804=item [2]
803805
804806=begin original
805807
806808NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
807809on the rules in effect. See
808810L<the beginning of this section|/Whitespace>.
809811
810812=end original
811813
812814NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に
813815マッチングしたりマッチングしなかったりします。
814816L<the beginning of this section|/Whitespace> を参照してください。
815817
816818=back
817819
818820=head3 Unicode Properties
819821
820822(Unicode 特性)
821823
822824=begin original
823825
824826C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
825827Unicode properties. One letter property names can be used in the C<\pP> form,
826828with the property name following the C<\p>, otherwise, braces are required.
827829When using braces, there is a single form, which is just the property name
828830enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
829831which means to match if the property "name" for the character has that particular
830832"value".
831833For instance, a match for a number can be written as C</\pN/> or as
832834C</\p{Number}/>, or as C</\p{Number=True}/>.
833835Lowercase letters are matched by the property I<Lowercase_Letter> which
834836has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
835837C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
836838(the underscores are optional).
837839C</\pLl/> is valid, but means something different.
838840It matches a two character string: a letter (Unicode property C<\pL>),
839841followed by a lowercase C<l>.
840842
841843=end original
842844
843845C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に
844846マッチングする文字クラスです。
845847一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ
846848中かっこが必要です。
847849中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、
848850C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を
849851持つものにマッチングすることになる複合形式があります。
850852例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または
851853C</\p{Number=True}/> と書けます。
852854小文字は I<LowercaseLetter> 特性にマッチングします; これには
853855I<Ll> と言う短縮形式があります。
854856中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または
855857C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。
856858C</\pLl/> も妥当ですが、違う意味になります。
857859これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて
858860小文字の C<l> です。
859861
860862=begin original
861863
862If locale rules are not in effect, the use of
864What a Unicode property matches is never subject to locale rules, and
863a Unicode property will force the regular expression into using Unicode
865if locale rules are not otherwise in effect, the use of a Unicode
864rules, if it isn't already.
866property will force the regular expression into using Unicode rules, if
867it isn't already.
865868
866869=end original
867870
871Unicode 特性が何にマッチングするかは決してロケールの規則に影響されず、
868872ロケール規則が有効でない場合、Unicode 特性を使うと
869873正規表現に (まだそうでなければ) Unicode 規則を使うように強制します。
870874
871875=begin original
872876
873877Note that almost all properties are immune to case-insensitive matching.
874878That is, adding a C</i> regular expression modifier does not change what
875they match. There are two sets that are affected. The first set is
879they match. But there are two sets that are affected. The first set is
876880C<Uppercase_Letter>,
877881C<Lowercase_Letter>,
878882and C<Titlecase_Letter>,
879883all of which match C<Cased_Letter> under C</i> matching.
880884The second set is
881885C<Uppercase>,
882886C<Lowercase>,
883887and C<Titlecase>,
884888all of which match C<Cased> under C</i> matching.
885889(The difference between these sets is that some things, such as Roman
886890numerals, come in both upper and lower case, so they are C<Cased>, but
887891aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
888892actually C<Letter_Number>s.)
889893This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
890894of which under C</i> match C<PosixAlpha>.
891895
892896=end original
893897
894898ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに
895899注意してください。
896900つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を
897901与えないということです。
898影響を与える二つの集合があります。
902しかし、影響を与える二つの集合があります。
899903一つ目の集合は
900904C<Uppercase_Letter>,
901905C<Lowercase_Letter>,
902906C<Titlecase_Letter> で、全て C</i> マッチングの下で
903907C<Cased_Letter> にマッチングします。
904908二つ目の集合は
905909C<Uppercase>,
906910C<Lowercase>,
907911C<Titlecase> で、全てC</i> マッチングの下で
908912C<Cased> にマッチングします。
909913(これらの集合の違いは、ローマ数字のような一部のものは、
910914大文字と小文字があるので C<Cased> ですが、
911915文字とは扱われないので C<Cased_Letter> ではありません。
912916これらは実際には C<Letter_Number> です。)
913917この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます;
914918これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。
915919
916920=begin original
917921
918922For more details on Unicode properties, see L<perlunicode/Unicode
919923Character Properties>; for a
920924complete list of possible properties, see
921925L<perluniprops/Properties accessible through \p{} and \P{}>,
922926which notes all forms that have C</i> differences.
923927It is also possible to define your own properties. This is discussed in
924928L<perlunicode/User-Defined Character Properties>.
925929
926930=end original
927931
928932Unicode 特性に関するさらなる詳細については、
929933L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な
930934一覧については、C</i> に違いのある全ての形式について記されている
931935L<perluniprops/Properties accessible through \p{} and \P{}> を参照して
932936ください。
933937独自の特性を定義することも可能です。
934938これは L<perlunicode/User-Defined Character Properties> で
935939議論されています。
936940
937941=begin original
938942
939943Unicode properties are defined (surprise!) only on Unicode code points.
940A warning is raised and all matches fail on non-Unicode code points
944Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats
941(those above the legal Unicode maximum of 0x10FFFF). This can be
945non-Unicode code points (those above the legal Unicode maximum of
942somewhat surprising,
9460x10FFFF) as if they were typical unassigned Unicode code points.
943947
944948=end original
945949
946950Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ
947951定義されています。
948 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えもの) への
952v5.20 から、C<\p> C<\P> に対してマッチングすとき、
949マッチングの失敗警告が発生します。
953Perl
950これは驚かされるものかもしれません。
954非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) を、
955典型的な未割り当て Unicode 符号位置であるかのように扱います。
951956
952 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails.
957=begin original
953 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails!
954958
959Prior to v5.20, Perl raised a warning and made all matches fail on
960non-Unicode code points. This could be somewhat surprising:
961
962=end original
963
964v5.20 より前では、非 Unicode 符号位置に対しては全てのマッチングは失敗して、
965Perl は警告を出していました。
966これは驚かされるものだったかもしれません。
967
968 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails on Perls < v5.20.
969 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails on Perls
970 # < v5.20
971
955972=begin original
956973
957Even though these two matches might be thought of as complements, they
974Even though these two matches might be thought of as complements, until
958are so only on Unicode code points.
975v5.20 they were so only on Unicode code points.
959976
960977=end original
961978
962979これら二つのマッチングは補集合と考えるかもしれませんが、
963これらは Unicode 符号位置だけで
980v5.20 まで、これらは Unicode 符号位置だけでした
964981
982=begin original
983
984Starting in perl v5.30, wildcards are allowed in Unicode property
985values. See L<perlunicode/Wildcards in Property Values>.
986
987=end original
988
989perl v5.30 から、Unicode 特性にワイルドカードを使えます。
990L<perlunicode/Wildcards in Property Values> を参照してください。
991
965992=head4 Examples
966993
967994(例)
968995
969996=begin original
970997
971998 "a" =~ /\w/ # Match, "a" is a 'word' character.
972999 "7" =~ /\w/ # Match, "7" is a 'word' character as well.
9731000 "a" =~ /\d/ # No match, "a" isn't a digit.
9741001 "7" =~ /\d/ # Match, "7" is a digit.
9751002 " " =~ /\s/ # Match, a space is whitespace.
9761003 "a" =~ /\D/ # Match, "a" is a non-digit.
9771004 "7" =~ /\D/ # No match, "7" is not a non-digit.
9781005 " " =~ /\S/ # No match, a space is not non-whitespace.
9791006
9801007=end original
9811008
9821009 "a" =~ /\w/ # マッチング; "a" は「単語」文字。
9831010 "7" =~ /\w/ # マッチング; "7" も「単語」文字。
9841011 "a" =~ /\d/ # マッチングしない; "a" は数字ではない。
9851012 "7" =~ /\d/ # マッチング; "7" は数字。
9861013 " " =~ /\s/ # マッチング; スペースは空白。
9871014 "a" =~ /\D/ # マッチング; "a" は非数字。
9881015 "7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
9891016 " " =~ /\S/ # マッチングしない; スペースは非空白ではない。
9901017
9911018=begin original
9921019
9931020 " " =~ /\h/ # Match, space is horizontal whitespace.
9941021 " " =~ /\v/ # No match, space is not vertical whitespace.
9951022 "\r" =~ /\v/ # Match, a return is vertical whitespace.
9961023
9971024=end original
9981025
9991026 " " =~ /\h/ # マッチング; スペースは水平空白。
10001027 " " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
10011028 "\r" =~ /\v/ # マッチング; 復帰は垂直空白。
10021029
10031030=begin original
10041031
10051032 "a" =~ /\pL/ # Match, "a" is a letter.
10061033 "a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.
10071034
10081035=end original
10091036
10101037 "a" =~ /\pL/ # マッチング; "a" は英字。
10111038 "a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。
10121039
10131040=begin original
10141041
10151042 "\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character
10161043 # 'THAI CHARACTER SO SO', and that's in
10171044 # Thai Unicode class.
10181045 "a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character.
10191046
10201047=end original
10211048
10221049 "\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字
10231050 # 'THAI CHARACTER SO SO' で、これは
10241051 # Thai Unicode クラスにある。
10251052 "a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。
10261053
10271054=begin original
10281055
10291056It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
10301057complete numbers or words. To match a number (that consists of digits),
10311058use C<\d+>; to match a word, use C<\w+>. But be aware of the security
10321059considerations in doing so, as mentioned above.
10331060
10341061=end original
10351062
10361063C<\d>, C<\w> などは数値や単語全体ではなく、1 文字にマッチングすることは
10371064強調する価値があります。
10381065(数字で構成される) 数値 にマッチングするには C<\d+> を使います;
10391066単語にマッチングするには C<\w+> を使います。
10401067しかし前述したように、そうする場合のセキュリティ問題について
10411068注意してください。
10421069
10431070=head2 Bracketed Character Classes
10441071
10451072(かっこ付き文字クラス)
10461073
10471074=begin original
10481075
10491076The third form of character class you can use in Perl regular expressions
10501077is the bracketed character class. In its simplest form, it lists the characters
10511078that may be matched, surrounded by square brackets, like this: C<[aeiou]>.
10521079This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Like the other
10531080character classes, exactly one character is matched.* To match
10541081a longer string consisting of characters mentioned in the character
10551082class, follow the character class with a L<quantifier|perlre/Quantifiers>. For
10561083instance, C<[aeiou]+> matches one or more lowercase English vowels.
10571084
10581085=end original
10591086
10601087Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ文字クラスです。
10611088もっとも単純な形式では、以下のように大かっこの中にマッチングする文字を
10621089リストします: C<[aeiou]>.
10631090これは C<a>, C<e>, C<i>, C<o>, C<u> のどれかにマッチングします。
10641091他の文字クラスと同様、正確に一つの文字にマッチングします。
10651092文字クラスで言及した文字で構成されるより長い文字列にマッチングするには、
10661093文字クラスに L<量指定子|perlre/Quantifiers> を付けます。
10671094例えば、C<[aeiou]+> は一つまたはそれ以上の小文字英語母音に
10681095マッチングします。
10691096
10701097=begin original
10711098
10721099Repeating a character in a character class has no
10731100effect; it's considered to be in the set only once.
10741101
10751102=end original
10761103
10771104文字クラスの中で文字を繰り返しても効果はありません; 一度だけ現れたものと
10781105考えられます。
10791106
10801107=begin original
10811108
10821109Examples:
10831110
10841111=end original
10851112
10861113例:
10871114
10881115=begin original
10891116
10901117 "e" =~ /[aeiou]/ # Match, as "e" is listed in the class.
10911118 "p" =~ /[aeiou]/ # No match, "p" is not listed in the class.
10921119 "ae" =~ /^[aeiou]$/ # No match, a character class only matches
10931120 # a single character.
10941121 "ae" =~ /^[aeiou]+$/ # Match, due to the quantifier.
10951122
10961123=end original
10971124
10981125 "e" =~ /[aeiou]/ # マッチング; "e" はクラスにある。
10991126 "p" =~ /[aeiou]/ # マッチングしない; "p" はクラスにない。
11001127 "ae" =~ /^[aeiou]$/ # マッチングしない; 一つの文字クラスは
11011128 # 一文字だけにマッチングする。
11021129 "ae" =~ /^[aeiou]+$/ # マッチング; 量指定子により。
11031130
11041131 -------
11051132
11061133=begin original
11071134
1108* There is an exception to a bracketed character class matching a
1135* There are two exceptions to a bracketed character class matching a
1109single character only. When the class is to match caselessly under C</i>
1136single character only. Each requires special handling by Perl to make
1110matching rules, and a character that is explicitly mentioned inside the
1137things work:
1111class matches a
1112multiple-character sequence caselessly under Unicode rules, the class
1113(when not L<inverted|/Negation>) will also match that sequence. For
1114example, Unicode says that the letter C<LATIN SMALL LETTER SHARP S>
1115should match the sequence C<ss> under C</i> rules. Thus,
11161138
11171139=end original
11181140
11191141* 大かっこ文字クラスは単一の文字にのみマッチングするということには
1120つの例外があります。
1142つの例外があります。
1143それぞれは Perl がうまく動くために特別な扱いが必要です:
1144
1145=over
1146
1147=item *
1148
1149=begin original
1150
1151When the class is to match caselessly under C</i> matching rules, and a
1152character that is explicitly mentioned inside the class matches a
1153multiple-character sequence caselessly under Unicode rules, the class
1154will also match that sequence. For example, Unicode says that the
1155letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss>
1156under C</i> rules. Thus,
1157
1158=end original
1159
11211160クラスが C</i> マッチング規則の下で大文字小文字を無視したマッチングを
11221161して、クラスの中で明示的に記述された文字が Unicode の規則の下で複数文字並びに
11231162大文字小文字を無視してマッチングするとき、
1124そのクラス (L<否定|/Negation> でない場合) はその並びにもマッチングします。
1163そのクラスはその並びにもマッチングします。
11251164例えば、Unicode は文字 C<LATIN SMALL LETTER SHARP S> は C</i> 規則の下では
11261165並び C<ss> にマッチングするとしています。
11271166従って:
11281167
11291168 'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i # Matches
11301169 'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i # Matches
11311170
11321171=begin original
11331172
1134For this to happen, the character must be explicitly specified, and not
1173For this to happen, the class must not be inverted (see L</Negation>)
1135be part of a multi-character range (not even as one of its endpoints).
1174and the character must be explicitly specified, and not be part of a
1136(L</Character Ranges> will be explained shortly.) Therefore,
1175multi-character range (not even as one of its endpoints). (L</Character
1176Ranges> will be explained shortly.) Therefore,
11371177
11381178=end original
11391179
1140これが起きるためには、その文字は明示的に指定され、複数文字範囲の一部
1180これが起きるためには、
1181そのクラスは否定 (L</Negation> 参照) ではなく、
1182その文字は明示的に指定され、複数文字範囲の一部
11411183(たとえその端でも)でない必要があります。
11421184(L</Character Ranges> は短く説明されています。)
11431185従って:
11441186
1145 'ss' =~ /\A[\0-\x{ff}]\z/i # Doesn't match
1187 'ss' =~ /\A[\0-\x{ff}]\z/ui # Doesn't match
1146 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/i # No match
1188 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui # No match
1147 'ss' =~ /\A[\xDF-\xDF]\z/i # Matches on ASCII platforms, since \XDF
1189 'ss' =~ /\A[\xDF-\xDF]\z/ui # Matches on ASCII platforms, since
1148 # is LATIN SMALL LETTER SHARP S, and the
1190 # \xDF is LATIN SMALL LETTER SHARP S,
1149 # range is just a single element
1191 # and the range is just a single
1192 # element
11501193
11511194=begin original
11521195
11531196Note that it isn't a good idea to specify these types of ranges anyway.
11541197
11551198=end original
11561199
11571200どちらにしろこれらの種類の範囲を指定するのは良い考えではありません。
11581201
1202=item *
1203
1204=begin original
1205
1206Some names known to C<\N{...}> refer to a sequence of multiple characters,
1207instead of the usual single character. When one of these is included in
1208the class, the entire sequence is matched. For example,
1209
1210=end original
1211
1212Some names known to
1213C<\N{...}> で知られているいくつかの名前は、通常の単一の文字ではなく、
1214複数の文字の並びを参照します。
1215その一つがこのクラスに含まれている場合、並び全体がマッチングします。
1216例えば:
1217
1218 "\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}"
1219 =~ / ^ [\N{TAMIL SYLLABLE KAU}] $ /x;
1220
1221=begin original
1222
1223matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence
1224consisting of the two characters matched against. Like the other
1225instance where a bracketed class can match multiple characters, and for
1226similar reasons, the class must not be inverted, and the named sequence
1227may not appear in a range, even one where it is both endpoints. If
1228these happen, it is a fatal error if the character class is within the
1229scope of L<C<use re 'strict>|re/'strict' mode>, or within an extended
1230L<C<(?[...])>|/Extended Bracketed Character Classes> class; otherwise
1231only the first code point is used (with a C<regexp>-type warning
1232raised).
1233
1234=end original
1235
1236これはマッチングします; なぜなら C<\N{TAMIL SYLLABLE KAU}> は
1237マッチングする二つの文字からなる名前付き並びだからです。
1238大かっこクラスが複数の文字にマッチングするその他の例と同じように、
1239そして同様の理由で、クラスは否定できず、
1240たとえ両端の間であっても名前付き並びは範囲の中には現れません。
1241これらが起きたとき、文字クラスが
1242L<C<use re 'strict>|re/'strict' mode> のスコープ内か、
1243拡張された L<C<(?[...])>|/Extended Bracketed Character Classes> クラスの
1244中の場合には致命的エラーになります;
1245さもなければ、最初の符号位置のみが使われます
1246(そして C<regexp> 系の警告が発生します)。
1247
1248=back
1249
11591250=head3 Special Characters Inside a Bracketed Character Class
11601251
11611252(かっこ付き文字クラスの中の特殊文字)
11621253
11631254=begin original
11641255
11651256Most characters that are meta characters in regular expressions (that
11661257is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
11671258their special meaning and can be used inside a character class without
11681259the need to escape them. For instance, C<[()]> matches either an opening
11691260parenthesis, or a closing parenthesis, and the parens inside the character
1170class don't group or capture.
1261class don't group or capture. Be aware that, unless the pattern is
1262evaluated in single-quotish context, variable interpolation will take
1263place before the bracketed class is parsed:
11711264
11721265=end original
11731266
11741267正規表現内でメタ文字(つまり、C<.>, C<*>, C<(> のように特別な意味を持つ
11751268文字)となるほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を
11761269失うので、エスケープする必要はありません。
11771270例えば、C<[()]> は開きかっこまたは閉じかっこにマッチングし、文字クラスの中の
11781271かっこはグループや捕捉にはなりません。
1272パターンがシングルクォート風コンテキストの中で評価されない限り、
1273変数展開は大かっこクラスがパースされる前に行われることに注意してください:
11791274
1275 $, = "\t| ";
1276 $x =~ m'[$,]'; # single-quotish: matches '$' or ','
1277 $x =~ q{[$,]}' # same
1278 $x =~ m/[$,]/; # double-quotish: Because we made an
1279 # assignment to $, above, this now
1280 # matches "\t", "|", or " "
1281
11801282=begin original
11811283
11821284Characters that may carry a special meaning inside a character class are:
11831285C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
11841286escaped with a backslash, although this is sometimes not needed, in which
11851287case the backslash may be omitted.
11861288
11871289=end original
11881290
11891291文字クラスの中でも特別な意味を持つ文字は:
11901292C<\>, C<^>, C<->, C<[>, C<]> で、以下で議論します。
11911293これらは逆スラッシュでエスケープできますが、不要な場合もあり、そのような
11921294場合では逆スラッシュは省略できます。
11931295
11941296=begin original
11951297
11961298The sequence C<\b> is special inside a bracketed character class. While
11971299outside the character class, C<\b> is an assertion indicating a point
11981300that does not have either two word characters or two non-word characters
11991301on either side, inside a bracketed character class, C<\b> matches a
12001302backspace character.
12011303
12021304=end original
12031305
12041306シーケンス C<\b> は大かっこ文字クラスの内側では特別です。
12051307文字クラスの外側では C<\b> 二つの単語文字か二つの非単語文字のどちらかではない
12061308位置を示す表明ですが、大かっこ文字クラスの内側では C<\b> は後退文字に
12071309マッチングします。
12081310
12091311=begin original
12101312
12111313The sequences
12121314C<\a>,
12131315C<\c>,
12141316C<\e>,
12151317C<\f>,
12161318C<\n>,
12171319C<\N{I<NAME>}>,
12181320C<\N{U+I<hex char>}>,
12191321C<\r>,
12201322C<\t>,
12211323and
12221324C<\x>
12231325are also special and have the same meanings as they do outside a
1224bracketed character class. (However, inside a bracketed character
1326bracketed character class.
1225class, if C<\N{I<NAME>}> expands to a sequence of characters, only the first
1226one in the sequence is used, with a warning.)
12271327
12281328=end original
12291329
12301330並び
12311331C<\a>,
12321332C<\c>,
12331333C<\e>,
12341334C<\f>,
12351335C<\n>,
12361336C<\N{I<NAME>}>,
12371337C<\N{U+I<hex char>}>,
12381338C<\r>,
12391339C<\t>,
12401340C<\x>
12411341も特別で、大かっこ文字クラスの外側と同じ意味を持ちます。
1242(しかし、大かっこ文字クラスの中では、
1243C<\N{I<NAME>}> が文字並びに展開されると、
1244並びの最初の一つだけが使われ、警告が発生します。)
12451342
12461343=begin original
12471344
12481345Also, a backslash followed by two or three octal digits is considered an octal
12491346number.
12501347
12511348=end original
12521349
12531350また、逆スラッシュに引き続いて 2 または 3 桁の 8 進数字があると 8 進数として
12541351扱われます。
12551352
12561353=begin original
12571354
12581355A C<[> is not special inside a character class, unless it's the start of a
12591356POSIX character class (see L</POSIX Character Classes> below). It normally does
12601357not need escaping.
12611358
12621359=end original
12631360
12641361C<[> は、POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
12651362開始でない限りは文字クラスの中では特別ではありません。
12661363これは普通エスケープは不要です。
12671364
12681365=begin original
12691366
12701367A C<]> is normally either the end of a POSIX character class (see
12711368L</POSIX Character Classes> below), or it signals the end of the bracketed
12721369character class. If you want to include a C<]> in the set of characters, you
12731370must generally escape it.
12741371
12751372=end original
12761373
12771374A C<]> は普通は POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
12781375終わりか、大かっこ文字クラスの終了を示すかどちらかです。
12791376文字集合に C<]> を含める必要がある場合、一般的には
12801377エスケープしなければなりません。
12811378
12821379=begin original
12831380
12841381However, if the C<]> is the I<first> (or the second if the first
12851382character is a caret) character of a bracketed character class, it
12861383does not denote the end of the class (as you cannot have an empty class)
12871384and is considered part of the set of characters that can be matched without
12881385escaping.
12891386
12901387=end original
12911388
12921389しかし、C<]> が大かっこ文字クラスの I<最初> (または最初の文字がキャレットなら
129313902 番目) の文字の場合、(空クラスを作ることはできないので)これはクラスの
12941391終了を意味せず、エスケープなしでマッチングできる文字の集合の一部と
12951392考えられます。
12961393
12971394=begin original
12981395
12991396Examples:
13001397
13011398=end original
13021399
13031400例:
13041401
13051402=begin original
13061403
13071404 "+" =~ /[+?*]/ # Match, "+" in a character class is not special.
1308 "\cH" =~ /[\b]/ # Match, \b inside in a character class.
1405 "\cH" =~ /[\b]/ # Match, \b inside in a character class
13091406 # is equivalent to a backspace.
1310 "]" =~ /[][]/ # Match, as the character class contains.
1407 "]" =~ /[][]/ # Match, as the character class contains
13111408 # both [ and ].
13121409 "[]" =~ /[[]]/ # Match, the pattern contains a character class
1313 # containing just ], and the character class is
1410 # containing just [, and the character class is
13141411 # followed by a ].
13151412
13161413=end original
13171414
13181415 "+" =~ /[+?*]/ # マッチング; 文字クラス内の "+" は特別ではない。
13191416 "\cH" =~ /[\b]/ # マッチング; 文字クラスの内側の \b は後退と
13201417 # 等価。
13211418 "]" =~ /[][]/ # マッチング; 文字クラスに [ と ] の両方を
13221419 # 含んでいる。
1323 "[]" =~ /[[]]/ # マッチング; パターンは ] だけを含んでいる
1420 "[]" =~ /[[]]/ # マッチング; パターンは [ だけを含んでいる
13241421 # 文字クラスと、それに引き続く
13251422 # ] からなる。
13261423
1424=head3 Bracketed Character Classes and the C</xx> pattern modifier
1425
1426=begin original
1427
1428Normally SPACE and TAB characters have no special meaning inside a
1429bracketed character class; they are just added to the list of characters
1430matched by the class. But if the L<C</xx>|perlre/E<sol>x and E<sol>xx>
1431pattern modifier is in effect, they are generally ignored and can be
1432added to improve readability. They can't be added in the middle of a
1433single construct:
1434
1435=end original
1436
1437通常、大かっこ文字クラスの内側では SPACE と TAB の文字は
1438特別な意味はありません; これらは単にクラスによってマッチングされる文字の
1439リストに加えられます。
1440しかし、L<C</xx>|perlre/E<sol>x and E<sol>xx> パターン修飾子が有効の場合、
1441これらは一般的に無視されるので、可読性を向上させるために追加できます。
1442これらは単一の構文の中には追加できません:
1443
1444 / [ \x{10 FFFF} ] /xx # WRONG!
1445
1446=begin original
1447
1448The SPACE in the middle of the hex constant is illegal.
1449
1450=end original
1451
145216 進定数の中の SPACE は不正です。
1453
1454=begin original
1455
1456To specify a literal SPACE character, you can escape it with a
1457backslash, like:
1458
1459=end original
1460
1461リテラルな SPACE 文字を指定するには、次のように逆スラッシュで
1462エスケープします:
1463
1464 /[ a e i o u \ ]/xx
1465
1466=begin original
1467
1468This matches the English vowels plus the SPACE character.
1469
1470=end original
1471
1472これは英語の母音と SPACE 文字に一致します。
1473
1474=begin original
1475
1476For clarity, you should already have been using C<\t> to specify a
1477literal tab, and C<\t> is unaffected by C</xx>.
1478
1479=end original
1480
1481確認すると、リテラルなタブのためには既に C<\t> を使っているべきで、
1482C<\t> は C</xx> の影響を受けません。
1483
13271484=head3 Character Ranges
13281485
13291486(文字範囲)
13301487
13311488=begin original
13321489
13331490It is not uncommon to want to match a range of characters. Luckily, instead
13341491of listing all characters in the range, one may use the hyphen (C<->).
13351492If inside a bracketed character class you have two characters separated
13361493by a hyphen, it's treated as if all characters between the two were in
13371494the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]>
13381495matches any lowercase letter from the first half of the ASCII alphabet.
13391496
13401497=end original
13411498
13421499文字のある範囲にマッチングしたいというのは珍しくありません。
13431500幸運なことに、その範囲の文字を全て一覧に書く代わりに、ハイフン (C<->) を
13441501使えます。
13451502大かっこ文字クラスの内側で二つの文字がハイフンで区切られていると、
13461503二つの文字の間の全ての文字がクラスに書かれているかのように扱われます。
13471504例えば、C<[0-9]> は任意の ASCII 数字にマッチングし、C<[a-m]> は
13481505ASCII アルファベットの前半分の小文字にマッチングします。
13491506
13501507=begin original
13511508
13521509Note that the two characters on either side of the hyphen are not
13531510necessarily both letters or both digits. Any character is possible,
13541511although not advisable. C<['-?]> contains a range of characters, but
13551512most people will not know which characters that means. Furthermore,
13561513such ranges may lead to portability problems if the code has to run on
13571514a platform that uses a different character set, such as EBCDIC.
13581515
13591516=end original
13601517
13611518ハイフンのそれぞれの側の二つの文字は両方とも英字であったり両方とも
13621519数字であったりする必要はないことに注意してください。
13631520任意の文字が可能ですが、勧められません。
13641521C<['-?]> は文字の範囲を含みますが、ほとんどの人はどの文字が含まれるか
13651522分かりません。
13661523さらに、このような範囲は、コードが EBCDIC のような異なった文字集合を使う
13671524プラットフォームで実行されると移植性の問題を引き起こします。
13681525
13691526=begin original
13701527
13711528If a hyphen in a character class cannot syntactically be part of a range, for
13721529instance because it is the first or the last character of the character class,
13731530or if it immediately follows a range, the hyphen isn't special, and so is
13741531considered a character to be matched literally. If you want a hyphen in
13751532your set of characters to be matched and its position in the class is such
13761533that it could be considered part of a range, you must escape that hyphen
13771534with a backslash.
13781535
13791536=end original
13801537
13811538例えば文字クラスの最初または最後であったり、範囲の直後のために、文字クラスの
13821539中のハイフンが文法的に範囲の一部となれない場合、ハイフンは特別ではなく、
13831540リテラルにマッチングするべき文字として扱われます。
13841541マッチングする文字の集合にハイフンを入れたいけれどもその位置が範囲の
13851542一部として考えられる場合はハイフンを逆スラッシュで
13861543エスケープしなければなりません。
13871544
13881545=begin original
13891546
13901547Examples:
13911548
13921549=end original
13931550
13941551例:
13951552
13961553=begin original
13971554
13981555 [a-z] # Matches a character that is a lower case ASCII letter.
13991556 [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or
14001557 # the letter 'z'.
14011558 [-z] # Matches either a hyphen ('-') or the letter 'z'.
14021559 [a-f-m] # Matches any letter between 'a' and 'f' (inclusive), the
14031560 # hyphen ('-'), or the letter 'm'.
14041561 ['-?] # Matches any of the characters '()*+,-./0123456789:;<=>?
14051562 # (But not on an EBCDIC platform).
1563 [\N{APOSTROPHE}-\N{QUESTION MARK}]
1564 # Matches any of the characters '()*+,-./0123456789:;<=>?
1565 # even on an EBCDIC platform.
1566 [\N{U+27}-\N{U+3F}] # Same. (U+27 is "'", and U+3F is "?")
14061567
14071568=end original
14081569
14091570 [a-z] # 小文字 ASCII 英字にマッチング。
14101571 [a-fz] # 'a' から 'f' の英字およびと 'z' の英字に
14111572 # マッチング。
14121573 [-z] # ハイフン ('-') または英字 'z' にマッチング。
14131574 [a-f-m] # 'a' から 'f' の英字、ハイフン ('-')、英字 'm' に
14141575 # マッチング。
14151576 ['-?] # 文字 '()*+,-./0123456789:;<=>? のどれかにマッチング
14161577 # (しかし EBCDIC プラットフォームでは異なります)。
1578 [\N{APOSTROPHE}-\N{QUESTION MARK}]
1579 # たとえ EBCDIC プラットフォームでも '()*+,-./0123456789:;<=>?
1580 # のいずれかの文字にマッチング。
1581 [\N{U+27}-\N{U+3F}] # 同じ。 (U+27 は "'", U+3F は "?")
14171582
1583=begin original
1584
1585As the final two examples above show, you can achieve portability to
1586non-ASCII platforms by using the C<\N{...}> form for the range
1587endpoints. These indicate that the specified range is to be interpreted
1588using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match
1589C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>,
1590and C<\N{U+3F}>, whatever the native code point versions for those are.
1591These are called "Unicode" ranges. If either end is of the C<\N{...}>
1592form, the range is considered Unicode. A C<regexp> warning is raised
1593under C<S<"use re 'strict'">> if the other endpoint is specified
1594non-portably:
1595
1596=end original
1597
1598前述の最後の二つの例が示すように、範囲の端点に
1599C<\N{...}> 形式を使用することで、非 ASCII プラットフォームへの
1600移植性を実現できます。
1601これらは、指定された範囲が Unicode 値を使用して解釈されることを示しています;
1602したがって、C<[\N{U+27}-\N{U+3F}]>は、C<\N{U+27}>、C<\N{U+28}>、
1603C<\N{U+29}>、...、C<\N{U+3D}>、C<\N{U+3E}>、C<\N{U+3F}> に
1604マッチングすることを意味します;
1605これらのネイティブ符号位置のバージョンが何であっても一致します。
1606これらは "Unicode" 範囲と呼ばれます。
1607いずれかの端点が C<\N{...}> 形式の場合、範囲は Unicode と見なされます。
1608もう一方の端点が移植性がない形で指定されている場合、
1609C<S<"use re 'strict'">> の下で C<regexp> 警告が発生します:
1610
1611 [\N{U+00}-\x09] # Warning under re 'strict'; \x09 is non-portable
1612 [\N{U+00}-\t] # No warning;
1613
1614=begin original
1615
1616Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ...
1617C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a
1618mistake so the warning is raised (under C<re 'strict'>) for it.
1619
1620=end original
1621
1622前述の両方とも文字 C<\N{U+00}> C<\N{U+01}>, ...
1623C<\N{U+08}>, C<\N{U+09}> にマッチングしますが、
1624C<\x09> は誤りのように見えるので、
1625(C<re 'strict'> の下で) 警告が発生します。
1626
1627=begin original
1628
1629Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any
1630subranges of these match what an English-only speaker would expect them
1631to match on any platform. That is, C<[A-Z]> matches the 26 ASCII
1632uppercase letters;
1633C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10
1634digits. Subranges, like C<[h-k]>, match correspondingly, in this case
1635just the four letters C<"h">, C<"i">, C<"j">, and C<"k">. This is the
1636natural behavior on ASCII platforms where the code points (ordinal
1637values) for C<"h"> through C<"k"> are consecutive integers (0x68 through
16380x6B). But special handling to achieve this may be needed on platforms
1639with a non-ASCII native character set. For example, on EBCDIC
1640platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is
16410x91, and C<"k"> is 0x92. Perl specially treats C<[h-k]> to exclude the
1642seven code points in the gap: 0x8A through 0x90. This special handling is
1643only invoked when the range is a subrange of one of the ASCII uppercase,
1644lowercase, and digit ranges, AND each end of the range is expressed
1645either as a literal, like C<"A">, or as a named character (C<\N{...}>,
1646including the C<\N{U+...> form).
1647
1648=end original
1649
1650Perl はまた、範囲 C<A-Z>、C<a-z>、C<0-9>、およびこれらの部分範囲が、
1651英語のみの話者が一致すると予想する範囲とどのプラットフォームでも
1652一致することを保証します。
1653つまり、C<[A-Z]> はASCII の大文字 26 文字と一致します;
1654C<[a-z]> は小文字 26 文字と一致します;
1655C<[0-9]>は 10 の数字と一致します。
1656C<[h-k]> のような部分範囲もこれに対応して一致します;
1657この場合、4 文字 C<"h">、C<"i">、C<"j">、C<"k"> だけが一致します。
1658これは、C<"h"> から C<"k"> までの符号位置(序数値)が連続した
1659整数(0x68 から 0x6B)である ASCII プラットフォームでの自然な動作です。
1660しかし、非 ASCII ネイティブ文字集合を持つプラットフォームでは、
1661これを実現するための特別な処理が必要になるかもしれません。
1662たとえば、EBCDIC プラットフォームでは、C<"h"> のコードポイントは
16630x88、C<"i"> は 0x89、C<"j"> は 0x91、C<"k"> は 0x92 です。
1664Perl は C<[h-k]> を特別に扱い、隙間にある七つの符号位置
1665(0x8A から 0x90)を除外します。
1666この特殊処理は、範囲が ASCII の大文字、小文字、数字の範囲の
1667いずれかの部分範囲であり、範囲の両端が C<"A"> のようなリテラル
1668または名前付き文字(C<\N{...}>(C<\N{U+...> 形式を含む))として表現されている
1669場合にのみ呼び出されます。
1670
1671=begin original
1672
1673EBCDIC Examples:
1674
1675=end original
1676
1677EBCDIC の例:
1678
1679 [i-j] # Matches either "i" or "j"
1680 [i-\N{LATIN SMALL LETTER J}] # Same
1681 [i-\N{U+6A}] # Same
1682 [\N{U+69}-\N{U+6A}] # Same
1683 [\x{89}-\x{91}] # Matches 0x89 ("i"), 0x8A .. 0x90, 0x91 ("j")
1684 [i-\x{91}] # Same
1685 [\x{89}-j] # Same
1686 [i-J] # Matches, 0x89 ("i") .. 0xC1 ("J"); special
1687 # handling doesn't apply because range is mixed
1688 # case
1689
14181690=head3 Negation
14191691
14201692(否定)
14211693
14221694=begin original
14231695
14241696It is also possible to instead list the characters you do not want to
14251697match. You can do so by using a caret (C<^>) as the first character in the
14261698character class. For instance, C<[^a-z]> matches any character that is not a
14271699lowercase ASCII letter, which therefore includes more than a million
14281700Unicode code points. The class is said to be "negated" or "inverted".
14291701
14301702=end original
14311703
14321704代わりにマッチングしたくない文字の一覧を指定することも可能です。
14331705文字クラスの先頭の文字としてキャレット (C<^>) を使うことで実現します。
14341706例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします;
14351707従って 100 万種類以上の Unicode 符号位置が含まれます。
14361708このクラスは「否定」("negated") や「反転」("inverted")と呼ばれます。
14371709
14381710=begin original
14391711
14401712This syntax make the caret a special character inside a bracketed character
14411713class, but only if it is the first character of the class. So if you want
14421714the caret as one of the characters to match, either escape the caret or
14431715else don't list it first.
14441716
14451717=end original
14461718
14471719この文法はキャレットを大かっこ文字クラスの内側で特別な文字にしますが、
14481720クラスの最初の文字の場合のみです。
14491721それでマッチングしたい文字の一つでキャレットを使いたい場合、キャレットを
14501722エスケープするか、最初以外の位置に書いてください。
14511723
14521724=begin original
14531725
14541726In inverted bracketed character classes, Perl ignores the Unicode rules
1455that normally say that certain characters should match a sequence of
1727that normally say that named sequence, and certain characters should
1456multiple characters under caseless C</i> matching. Following those
1728match a sequence of multiple characters use under caseless C</i>
1457rules could lead to highly confusing situations:
1729matching. Following those rules could lead to highly confusing
1730situations:
14581731
14591732=end original
14601733
14611734否定大かっこ文字クラスでは、通常は大文字小文字を無視した C</i> マッチングの
1462下ではある種の文字が複数の文字並びにマッチングするということを
1735下では名前空間とある種の文字が複数の文字並びにマッチングするということを
14631736Perl は無視します。
14641737これらの規則に従うととても混乱する状況を引き起こすことになるからです:
14651738
14661739 "ss" =~ /^[^\xDF]+$/ui; # Matches!
14671740
14681741=begin original
14691742
14701743This should match any sequences of characters that aren't C<\xDF> nor
14711744what C<\xDF> matches under C</i>. C<"s"> isn't C<\xDF>, but Unicode
14721745says that C<"ss"> is what C<\xDF> matches under C</i>. So which one
14731746"wins"? Do you fail the match because the string has C<ss> or accept it
14741747because it has an C<s> followed by another C<s>? Perl has chosen the
1475latter.
1748latter. (See note in L</Bracketed Character Classes> above.)
14761749
14771750=end original
14781751
14791752これは C</i> の下では C<\xDF> または C<\xDF> にマッチングするもの以外の
14801753任意の文字並びにマッチングするべきです。
14811754C<"s"> は C<\xDF> ではありませんが、
14821755C</i> の下では C<"ss"> は C<\xDF> がマッチングするものと Unicode は
14831756言っています。
14841757ではどちらが「勝つ」のでしょうか?
14851758文字列は C<ss> だからマッチングに失敗するのでしょうか、
14861759それともこれは C<s> の後にもう一つの C<s> があるから成功するのでしょうか?
14871760Perl は後者を選択しました。
1761(前述の L</Bracketed Character Classes> を参照してください。)
14881762
14891763=begin original
14901764
14911765Examples:
14921766
14931767=end original
14941768
14951769例:
14961770
14971771=begin original
14981772
14991773 "e" =~ /[^aeiou]/ # No match, the 'e' is listed.
15001774 "x" =~ /[^aeiou]/ # Match, as 'x' isn't a lowercase vowel.
15011775 "^" =~ /[^^]/ # No match, matches anything that isn't a caret.
15021776 "^" =~ /[x^]/ # Match, caret is not special here.
15031777
15041778=end original
15051779
15061780 "e" =~ /[^aeiou]/ # マッチングしない; 'e' がある。
15071781 "x" =~ /[^aeiou]/ # マッチング; 'x' は小文字の母音ではない。
15081782 "^" =~ /[^^]/ # マッチングしない; キャレット以外全てにマッチング。
15091783 "^" =~ /[x^]/ # マッチング; キャレットはここでは特別ではない。
15101784
15111785=head3 Backslash Sequences
15121786
15131787(逆スラッシュシーケンス)
15141788
15151789=begin original
15161790
15171791You can put any backslash sequence character class (with the exception of
15181792C<\N> and C<\R>) inside a bracketed character class, and it will act just
15191793as if you had put all characters matched by the backslash sequence inside the
15201794character class. For instance, C<[a-f\d]> matches any decimal digit, or any
15211795of the lowercase letters between 'a' and 'f' inclusive.
15221796
15231797=end original
15241798
15251799大かっこ文字クラスの中に(C<\N> と C<\R> を例外として)逆スラッシュシーケンス
15261800文字クラスを置くことができ、逆スラッシュシーケンスにマッチングする全ての
15271801文字を文字クラスの中に置いたかのように動作します。
15281802例えば、C<[a-f\d]> は任意の 10 進数字、あるいは 'a' から 'f' までの小文字に
15291803マッチングします。
15301804
15311805=begin original
15321806
15331807C<\N> within a bracketed character class must be of the forms C<\N{I<name>}>
15341808or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines,
15351809for the same reason that a dot C<.> inside a bracketed character class loses
15361810its special meaning: it matches nearly anything, which generally isn't what you
15371811want to happen.
15381812
15391813=end original
15401814
15411815大かっこ文字クラスの中のドット C<.> が特別な意味を持たないのと同じ理由で、
15421816大かっこ文字クラスの中の C<\N> は C<\N{I<name>}> または
15431817C<\N{U+I<hex char>}> の形式で、かつ非改行マッチング形式でない形でなければ
15441818なりません: これはほとんど何でもマッチングするので、一般的には起こって
15451819欲しいことではありません。
15461820
15471821=begin original
15481822
15491823Examples:
15501824
15511825=end original
15521826
15531827例:
15541828
15551829=begin original
15561830
15571831 /[\p{Thai}\d]/ # Matches a character that is either a Thai
15581832 # character, or a digit.
15591833 /[^\p{Arabic}()]/ # Matches a character that is neither an Arabic
15601834 # character, nor a parenthesis.
15611835
15621836=end original
15631837
15641838 /[\p{Thai}\d]/ # タイ文字または数字の文字に
15651839 # マッチングする。
15661840 /[^\p{Arabic}()]/ # アラビア文字でもかっこでもない文字に
15671841 # マッチングする。
15681842
15691843=begin original
15701844
15711845Backslash sequence character classes cannot form one of the endpoints
15721846of a range. Thus, you can't say:
15731847
15741848=end original
15751849
15761850逆スラッシュシーケンス文字クラスは範囲の端点の一つにはできません。
15771851従って、以下のようにはできません:
15781852
15791853 /[\p{Thai}-\d]/ # Wrong!
15801854
15811855=head3 POSIX Character Classes
15821856X<character class> X<\p> X<\p{}>
15831857X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph>
15841858X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit>
15851859
15861860(POSIX 文字クラス)
15871861
15881862=begin original
15891863
1590POSIX character classes have the form C<[:class:]>, where I<class> is
1864POSIX character classes have the form C<[:class:]>, where I<class> is the
15911865name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear
15921866I<inside> bracketed character classes, and are a convenient and descriptive
15931867way of listing a group of characters.
15941868
15951869=end original
15961870
15971871POSIX 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は
15981872デリミタです。
15991873POSIX 文字クラスは大かっこ文字クラスの I<内側> にのみ現れ、文字のグループを
16001874一覧するのに便利で記述的な方法です。
16011875
16021876=begin original
16031877
16041878Be careful about the syntax,
16051879
16061880=end original
16071881
16081882文法について注意してください、
16091883
16101884 # Correct:
16111885 $string =~ /[[:alpha:]]/
16121886
16131887 # Incorrect (will warn):
16141888 $string =~ /[:alpha:]/
16151889
16161890=begin original
16171891
16181892The latter pattern would be a character class consisting of a colon,
16191893and the letters C<a>, C<l>, C<p> and C<h>.
16201894POSIX character classes can be part of a larger bracketed character class.
16211895For example,
16221896
16231897=end original
16241898
16251899後者のパターンは、コロンおよび C<a>, C<l>, C<p>, C<h> の文字からなる
16261900文字クラスです。
16271901これら文字クラスはより大きな大かっこ文字クラスの一部にできます。
1628例えば
1902例えば:
16291903
16301904 [01[:alpha:]%]
16311905
16321906=begin original
16331907
16341908is valid and matches '0', '1', any alphabetic character, and the percent sign.
16351909
16361910=end original
16371911
16381912これは妥当で、'0'、'1'、任意の英字、パーセントマークにマッチングします。
16391913
16401914=begin original
16411915
16421916Perl recognizes the following POSIX character classes:
16431917
16441918=end original
16451919
16461920Perl は以下の POSIX 文字クラスを認識します:
16471921
16481922=begin original
16491923
1650 alpha Any alphabetical character ("[A-Za-z]").
1924 alpha Any alphabetical character (e.g., [A-Za-z]).
1651 alnum Any alphanumeric character ("[A-Za-z0-9]").
1925 alnum Any alphanumeric character (e.g., [A-Za-z0-9]).
16521926 ascii Any character in the ASCII character set.
1653 blank A GNU extension, equal to a space or a horizontal tab ("\t").
1927 blank Any horizontal whitespace character (e.g. space or horizontal
1928 tab ("\t")).
16541929 cntrl Any control character. See Note [2] below.
1655 digit Any decimal digit ("[0-9]"), equivalent to "\d".
1930 digit Any decimal digit (e.g., [0-9]), equivalent to "\d".
16561931 graph Any printable character, excluding a space. See Note [3] below.
1657 lower Any lowercase character ("[a-z]").
1932 lower Any lowercase character (e.g., [a-z]).
16581933 print Any printable character, including a space. See Note [4] below.
16591934 punct Any graphical character excluding "word" characters. Note [5].
16601935 space Any whitespace character. "\s" including the vertical tab
16611936 ("\cK").
1662 upper Any uppercase character ("[A-Z]").
1937 upper Any uppercase character (e.g., [A-Z]).
1663 word A Perl extension ("[A-Za-z0-9_]"), equivalent to "\w".
1938 word A Perl extension (e.g., [A-Za-z0-9_]), equivalent to "\w".
1664 xdigit Any hexadecimal digit ("[0-9a-fA-F]").
1939 xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]). Note [7].
16651940
16661941=end original
16671942
1668 alpha 任意の英字 ("[A-Za-z]")。
1943 alpha 任意の英字 (例: [A-Za-z])。
1669 alnum 任意の英数字。("[A-Za-z0-9]")
1944 alnum 任意の英数字。(例: [A-Za-z0-9])
16701945 ascii 任意の ASCII 文字集合の文字。
1671 blank GNU 拡張; スペースまたは水平タブ ("\t") と同じ。
1946 blank 任意の水平空白文字 (スペース水平タブ ("\t") など)
16721947 cntrl 任意の制御文字。後述の [2] 参照。
1673 digit 任意の 10 進数字 ("[0-9]"); "\d" と等価。
1948 digit 任意の 10 進数字 (例: [0-9]); "\d" と等価。
16741949 graph 任意の表示文字; スペースを除く。後述の [3] 参照。
1675 lower 任意の小文字 ("[a-z]")。
1950 lower 任意の小文字 (例: [a-z])。
16761951 print 任意の表示文字; スペースを含む。後述の [4] 参照。
16771952 punct 任意の「単語」文字を除く表示文字。[5] 参照。
16781953 space 任意の空白文字。水平タブ ("\cK") を含む "\s"。
1679 upper 任意の大文字 ("[A-Z]")。
1954 upper 任意の大文字 (例: [A-Z])。
1680 word Perl 拡張 ("[A-Za-z0-9_]"); "\w" と等価。
1955 word Perl 拡張 (例: [A-Za-z0-9_]); "\w" と等価。
1681 xdigit 任意の 16 進文字 ("[0-9a-fA-F]")。
1956 xdigit 任意の 16 進文字 (例: [0-9a-fA-F])。[7] 参照
16821957
16831958=begin original
16841959
1960Like the L<Unicode properties|/Unicode Properties>, most of the POSIX
1961properties match the same regardless of whether case-insensitive (C</i>)
1962matching is in effect or not. The two exceptions are C<[:upper:]> and
1963C<[:lower:]>. Under C</i>, they each match the union of C<[:upper:]> and
1964C<[:lower:]>.
1965
1966=end original
1967
1968L<Unicode properties|/Unicode Properties> と同様、
1969ほとんどの POSIX 特性は、大文字小文字無視 (C</i>) が有効かどうかに関わらず
1970同じものにマッチングします。
1971二つの例外は C<[:upper:]> と C<[:lower:]> です。
1972C</i> の下では、これらそれぞれ C<[:upper:]> と C<[:lower:]> の和集合に
1973マッチングします。
1974
1975=begin original
1976
16851977Most POSIX character classes have two Unicode-style C<\p> property
16861978counterparts. (They are not official Unicode properties, but Perl extensions
16871979derived from official Unicode properties.) The table below shows the relation
16881980between POSIX character classes and these counterparts.
16891981
16901982=end original
16911983
16921984ほとんどの POSIX 文字クラスには、対応する二つの Unicode 式の C<\p> 特性が
16931985あります。
16941986(これは公式 Unicode 特性ではなく、公式 Unicode 特性から派生した Perl
16951987エクステンションです。)
16961988以下の表は POSIX 文字クラスと対応するものとの関連を示します。
16971989
16981990=begin original
16991991
17001992One counterpart, in the column labelled "ASCII-range Unicode" in
17011993the table, matches only characters in the ASCII character set.
17021994
17031995=end original
17041996
17051997対応物の一つである、表で "ASCII-range Unicode" と書かれた列のものは、
17061998ASCII 文字集合の文字にのみマッチングします。
17071999
17082000=begin original
17092001
17102002The other counterpart, in the column labelled "Full-range Unicode", matches any
17112003appropriate characters in the full Unicode character set. For example,
17122004C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any
17132005character in the entire Unicode character set considered alphabetic.
17142006An entry in the column labelled "backslash sequence" is a (short)
17152007equivalent.
17162008
17172009=end original
17182010
17192011もう一つの対応物である、"Full-range Unicode" と書かれた列のものは、
17202012Unicode 文字集合全体の中の適切な任意の文字にマッチングします。
17212013例えば、C<\p{Alpha}> は単に ASCII アルファベット文字だけでなく、
17222014Unicode 文字集合全体の中からアルファベットと考えられる任意の文字に
17232015マッチングします。
17242016"backslash sequence" の列は (短い) 同義語です。
17252017
17262018 [[:...:]] ASCII-range Full-range backslash Note
17272019 Unicode Unicode sequence
17282020 -----------------------------------------------------
17292021 alpha \p{PosixAlpha} \p{XPosixAlpha}
17302022 alnum \p{PosixAlnum} \p{XPosixAlnum}
17312023 ascii \p{ASCII}
17322024 blank \p{PosixBlank} \p{XPosixBlank} \h [1]
17332025 or \p{HorizSpace} [1]
17342026 cntrl \p{PosixCntrl} \p{XPosixCntrl} [2]
17352027 digit \p{PosixDigit} \p{XPosixDigit} \d
17362028 graph \p{PosixGraph} \p{XPosixGraph} [3]
17372029 lower \p{PosixLower} \p{XPosixLower}
17382030 print \p{PosixPrint} \p{XPosixPrint} [4]
17392031 punct \p{PosixPunct} \p{XPosixPunct} [5]
17402032 \p{PerlSpace} \p{XPerlSpace} \s [6]
17412033 space \p{PosixSpace} \p{XPosixSpace} [6]
17422034 upper \p{PosixUpper} \p{XPosixUpper}
17432035 word \p{PosixWord} \p{XPosixWord} \w
1744 xdigit \p{PosixXDigit} \p{XPosixXDigit}
2036 xdigit \p{PosixXDigit} \p{XPosixXDigit} [7]
17452037
17462038=over 4
17472039
17482040=item [1]
17492041
17502042=begin original
17512043
17522044C<\p{Blank}> and C<\p{HorizSpace}> are synonyms.
17532045
17542046=end original
17552047
17562048C<\p{Blank}> と C<\p{HorizSpace}> は同義語です。
17572049
17582050=item [2]
17592051
17602052=begin original
17612053
17622054Control characters don't produce output as such, but instead usually control
17632055the terminal somehow: for example, newline and backspace are control characters.
1764In the ASCII range, characters whose code points are between 0 and 31 inclusive,
2056On ASCII platforms, in the ASCII range, characters whose code points are
1765plus 127 (C<DEL>) are control characters.
2057between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on
2058EBCDIC platforms, their counterparts are control characters.
17662059
17672060=end original
17682061
17692062制御文字はそれ自体は出力されず、普通は何か端末を制御します: 例えば
17702063改行と後退は制御文字です。
1771ASCII の範囲では、符号位置が 0 から 31 までの範囲の文字および 127 (C<DEL>) が
2064ASCII プラットフォームで、ASCII の範囲では、符号位置が 0 から 31 までの
1772制御文字です
2065範囲の文字および 127 (C<DEL>) が制御文字です;
2066EBCDIC プラットフォームでは、対応するものは制御文字です。
17732067
17742068=item [3]
17752069
17762070=begin original
17772071
17782072Any character that is I<graphical>, that is, visible. This class consists
17792073of all alphanumeric characters and all punctuation characters.
17802074
17812075=end original
17822076
17832077I<graphical>、つまり見える文字。
17842078このクラスは全ての英数字と全ての句読点文字。
17852079
17862080=item [4]
17872081
17882082=begin original
17892083
17902084All printable characters, which is the set of all graphical characters
17912085plus those whitespace characters which are not also controls.
17922086
17932087=end original
17942088
17952089全ての表示可能な文字; 全ての graphical 文字に加えて制御文字でない空白文字。
17962090
17972091=item [5]
17982092
17992093=begin original
18002094
18012095C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all
18022096non-controls, non-alphanumeric, non-space characters:
18032097C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect,
18042098it could alter the behavior of C<[[:punct:]]>).
18052099
18062100=end original
18072101
18082102ASCII の範囲の C<\p{PosixPunct}> と C<[[:punct:]]> は全ての非制御、非英数字、
18092103非空白文字にマッチングします:
18102104C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (しかしロケールが有効なら、
18112105C<[[:punct:]]> の振る舞いが変わります)。
18122106
18132107=begin original
18142108
18152109The similarly named property, C<\p{Punct}>, matches a somewhat different
18162110set in the ASCII range, namely
18172111C<[-!"#%&'()*,./:;?@[\\\]_{}]>. That is, it is missing the nine
18182112characters C<[$+E<lt>=E<gt>^`|~]>.
18192113This is because Unicode splits what POSIX considers to be punctuation into two
18202114categories, Punctuation and Symbols.
18212115
18222116=end original
18232117
18242118似たような名前の特性 C<\p{Punct}> は、ASCII 範囲の異なる集合である
18252119C<[-!"#%&'()*,./:;?@[\\\]_{}]> にマッチングします。
18262120つまり、C<[$+E<lt>=E<gt>^`|~]> の 9 文字はありません。
18272121これは、Unicode は POSIX が句読点と考えるものを二つのカテゴリ
18282122Punctuation と Symbols に分けているからです。
18292123
18302124=begin original
18312125
18322126C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what
18332127C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}>
18342128matches. This is different than strictly matching according to
18352129C<\p{Punct}>. Another way to say it is that
18362130if Unicode rules are in effect, C<[[:punct:]]> matches all characters
18372131that Unicode considers punctuation, plus all ASCII-range characters that
18382132Unicode considers symbols.
18392133
18402134=end original
18412135
18422136C<\p{XPosixPunct}> と (Unicode の規則の下での) C<[[:punct:]]> は、
18432137ASCII の範囲で C<\p{PosixPunct}> がマッチングする物に加えて、
18442138C<\p{Punct}> がマッチングする物にマッチングします。
18452139これは C<\p{Punct}> に従って正確にマッチングする物と異なります。
18462140Unicode 規則が有効な場合のもう一つの言い方は、C<[[:punct:]]> は Unicode が
18472141句読点として扱うものに加えて、Unicode が "symbols" として扱う ASCII 範囲の
18482142全ての文字にマッチングします。
18492143
18502144=item [6]
18512145
18522146=begin original
18532147
1854C<\p{SpacePerl}> and C<\p{Space}> match identically starting with Perl
2148C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl
18552149v5.18. In earlier versions, these differ only in that in non-locale
1856matching, C<\p{SpacePerl}> does not match the vertical tab, C<\cK>.
2150matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>.
18572151Same for the two ASCII-only range forms.
18582152
18592153=end original
18602154
1861C<\p{SpacePerl}> と C<\p{Space}> は、Perl v5.18 からは同じように
2155C<\p{XPerlSpace}> と C<\p{Space}> は、Perl v5.18 からは同じように
18622156マッチングします。
18632157以前のバージョンでは、これらの違いは、非ロケールマッチングでは
1864C<\p{SpacePerl}> は垂直タブ C<\cK> にもマッチングしないということだけです。
2158C<\p{XPerlSpace}> は垂直タブ C<\cK> にもマッチングしないということだけです。
18652159二つの ASCII のみの範囲の形式では同じです。
18662160
2161=item [7]
2162
2163=begin original
2164
2165Unlike C<[[:digit:]]> which matches digits in many writing systems, such
2166as Thai and Devanagari, there are currently only two sets of hexadecimal
2167digits, and it is unlikely that more will be added. This is because you
2168not only need the ten digits, but also the six C<[A-F]> (and C<[a-f]>)
2169to correspond. That means only the Latin script is suitable for these,
2170and Unicode has only two sets of these, the familiar ASCII set, and the
2171fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO).
2172
2173=end original
2174
2175タイ文字やデバナーガリ文字のように多くの書記体系の数字にマッチングする
2176C<[[:digit:]]> と異なり、16 進数の二つの集合だけで、これ以上追加されることは
2177おそらくありません。
2178これは、対応するのに 10 の数字だけでなく、6 個の C<[A-F]> (および C<[a-f]>) も
2179必要だからです。
2180これは、Latin 用字のみがこれらに適合していて、
2181Unicode はこれらの二つの集合、つまり慣れ親しんだ
2182ASCII 集合と、U+FF10 (FULLWIDTH DIGIT ZERO) から始まる全角形式のみを
2183持つということです。
2184
18672185=back
18682186
18692187=begin original
18702188
18712189There are various other synonyms that can be used besides the names
1872listed in the table. For example, C<\p{PosixAlpha}> can be written as
2190listed in the table. For example, C<\p{XPosixAlpha}> can be written as
18732191C<\p{Alpha}>. All are listed in
1874L<perluniprops/Properties accessible through \p{} and \P{}>,
2192L<perluniprops/Properties accessible through \p{} and \P{}>.
1875plus all characters matched by each ASCII-range property.
18762193
18772194=end original
18782195
18792196表に挙げられている名前以外にも様々なその他の同義語が使えます。
1880例えば、C<\p{PosixAlpha}> は C<\p{Alpha}> と書けます。
2197例えば、C<\p{XPosixAlpha}> は C<\p{Alpha}> と書けます。
1881全ての一覧に加えて各 ASCII の範囲の特性にマッチングする全ての文字
2198全ての一覧は
1882L<perluniprops/Properties accessible through \p{} and \P{}> に
2199L<perluniprops/Properties accessible through \p{} and \P{}> に
18832200あります。
18842201
18852202=begin original
18862203
18872204Both the C<\p> counterparts always assume Unicode rules are in effect.
18882205On ASCII platforms, this means they assume that the code points from 128
18892206to 255 are Latin-1, and that means that using them under locale rules is
18902207unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the
18912208POSIX character classes are useful under locale rules. They are
18922209affected by the actual rules in effect, as follows:
18932210
18942211=end original
18952212
18962213C<\p> に対応するものの両方は常に Unicode の規則が有効であることを仮定します。
18972214これは、ASCII プラットフォームでは、128 から 255 の符号位置は
18982215Latin-1 であることを仮定するということで、ロケールの規則の下で
18992216これらを使うということは、ロケールが Latin-1 か UTF-8 であることが
19002217補償されていない限り賢明ではないということです。
19012218一方、POSIX 文字クラスはロケールの規則の下で有用です。
19022219これらは次のように、実際に有効な規則に影響を受けます:
19032220
19042221=over
19052222
19062223=item If the C</a> modifier, is in effect ...
19072224
19082225(C</a> が有効なら...)
19092226
19102227=begin original
19112228
19122229Each of the POSIX classes matches exactly the same as their ASCII-range
19132230counterparts.
19142231
19152232=end original
19162233
19172234それぞれの POSIX クラスは ASCII の範囲で対応する正確に同じものに
19182235マッチングします。
19192236
19202237=item otherwise ...
19212238
19222239(さもなければ ...)
19232240
19242241=over
19252242
19262243=item For code points above 255 ...
19272244
19282245(256 以上の符号位置では ...)
19292246
19302247=begin original
19312248
19322249The POSIX class matches the same as its Full-range counterpart.
19332250
19342251=end original
19352252
19362253POSIX クラスはその Full の範囲で対応する同じものにマッチングします。
19372254
19382255=item For code points below 256 ...
19392256
19402257(255 以下の符号位置では ...)
19412258
19422259=over
19432260
19442261=item if locale rules are in effect ...
19452262
19462263(ロケール規則が有効なら ...)
19472264
19482265=begin original
19492266
1950The POSIX class matches according to the locale, except that
2267The POSIX class matches according to the locale, except:
1951C<word> uses the platform's native underscore character, no matter what
2269=end original
2270
2271POSIX クラスはロケールに従ってマッチングします; 例外は:
2272
2273=over
2274
2275=item C<word>
2276
2277=begin original
2278
2279also includes the platform's native underscore character, no matter what
19522280the locale is.
19532281
19542282=end original
19552283
1956POSIX クラスはロケールに従ってマチングします;
2284それに加えて、ロケールが何か関わらず、プラトフォームのネイティブな
1957except that
1958C<word> はロケールが何かに関わらず、プラットフォームのネイティブな
19592285下線文字を使います。
19602286
1961=item if Unicode rules are in effect ...
2287=item C<ascii>
19622288
1963(Unicode 規則が有効なら ...)
2289=begin original
19642290
2291on platforms that don't have the POSIX C<ascii> extension, this matches
2292just the platform's native ASCII-range characters.
2293
2294=end original
2295
2296POSIX C<ascii> 拡張を持たないプラットフォームでは、
2297これは単にプラットフォームのネイティブな ASCII の範囲の文字に
2298マッチングします。
2299
2300=item C<blank>
2301
19652302=begin original
19662303
2304on platforms that don't have the POSIX C<blank> extension, this matches
2305just the platform's native tab and space characters.
2306
2307=end original
2308
2309on platforms that don't have the
2310POSIX C<blank> 格調を持たないプラットフォームでは、
2311これは単にプラットフォームのネイティブなタブとすぺーす文字に
2312マッチングします。
2313
2314=back
2315
2316=item if, instead, Unicode rules are in effect ...
2317
2318(そうではなく、Unicode 規則が有効なら ...)
2319
2320=begin original
2321
19672322The POSIX class matches the same as the Full-range counterpart.
19682323
19692324=end original
19702325
19712326POSIX クラスは Full の範囲の対応する同じものにマッチングします。
19722327
19732328=item otherwise ...
19742329
19752330(さもなければ ...)
19762331
19772332=begin original
19782333
19792334The POSIX class matches the same as the ASCII range counterpart.
19802335
19812336=end original
19822337
19832338POSIX クラスは ASCII の範囲の同じものにマッチングします。
19842339
19852340=back
19862341
19872342=back
19882343
19892344=back
19902345
19912346=begin original
19922347
19932348Which rules apply are determined as described in
19942349L<perlre/Which character set modifier is in effect?>.
19952350
19962351=end original
19972352
19982353どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
19992354記述されている方法で決定されます。
20002355
2001=begin original
2002
2003It is proposed to change this behavior in a future release of Perl so that
2004whether or not Unicode rules are in effect would not change the
2005behavior: Outside of locale, the POSIX classes
2006would behave like their ASCII-range counterparts. If you wish to
2007comment on this proposal, send email to C<perl5-porters@perl.org>.
2008
2009=end original
2010
2011Perl の将来のバージョンではこの振る舞いを変えることが提案されています;
2012Unicode の規則が有効かどうかは振る舞いを変えません:
2013ロケールの外側では、
2014POSIX クラスはその ASCII の範囲の対応するものと同様に振る舞います。
2015この提案にコメントしたいなら、C<perl5-porters@perl.org> にメールを
2016送ってください。
2017
20182356=head4 Negation of POSIX character classes
20192357X<character class, negation>
20202358
20212359(POSIX 文字クラスの否定)
20222360
20232361=begin original
20242362
20252363A Perl extension to the POSIX character class is the ability to
20262364negate it. This is done by prefixing the class name with a caret (C<^>).
20272365Some examples:
20282366
20292367=end original
20302368
20312369POSIX 文字クラスに対する Perl の拡張は否定の機能です。
20322370これはクラス名の前にキャレット (C<^>) を置くことで実現します。
20332371いくつかの例です:
20342372
20352373 POSIX ASCII-range Full-range backslash
20362374 Unicode Unicode sequence
20372375 -----------------------------------------------------
20382376 [[:^digit:]] \P{PosixDigit} \P{XPosixDigit} \D
20392377 [[:^space:]] \P{PosixSpace} \P{XPosixSpace}
20402378 \P{PerlSpace} \P{XPerlSpace} \S
20412379 [[:^word:]] \P{PerlWord} \P{XPosixWord} \W
20422380
20432381=begin original
20442382
20452383The backslash sequence can mean either ASCII- or Full-range Unicode,
20462384depending on various factors as described in L<perlre/Which character set modifier is in effect?>.
20472385
20482386=end original
20492387
20502388逆スラッシュシーケンスは ASCII- か Full-range Unicode のどちらかを意味します;
20512389どちらが使われるかは L<perlre/Which character set modifier is in effect?> で
20522390記述されている様々な要素に依存します。
20532391
20542392=head4 [= =] and [. .]
20552393
20562394([= =] と [. .])
20572395
20582396=begin original
20592397
20602398Perl recognizes the POSIX character classes C<[=class=]> and
20612399C<[.class.]>, but does not (yet?) support them. Any attempt to use
20622400either construct raises an exception.
20632401
20642402=end original
20652403
20662404Perl は POSIX 文字クラス C<[=class=]> と C<[.class.]> を認識しますが、
20672405これらには(まだ?)対応していません。
20682406このような構文を使おうとすると例外が発生します。
20692407
20702408=head4 Examples
20712409
20722410(例)
20732411
20742412=begin original
20752413
20762414 /[[:digit:]]/ # Matches a character that is a digit.
20772415 /[01[:lower:]]/ # Matches a character that is either a
20782416 # lowercase letter, or '0' or '1'.
20792417 /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
20802418 # except the letters 'a' to 'f' and 'A' to
20812419 # 'F'. This is because the main character
20822420 # class is composed of two POSIX character
20832421 # classes that are ORed together, one that
20842422 # matches any digit, and the other that
20852423 # matches anything that isn't a hex digit.
20862424 # The OR adds the digits, leaving only the
20872425 # letters 'a' to 'f' and 'A' to 'F' excluded.
20882426
20892427=end original
20902428
20912429 /[[:digit:]]/ # 数字の文字にマッチングする。
20922430 /[01[:lower:]]/ # 小文字、'0'、'1' のいずれかの文字に
20932431 # マッチングする。
20942432 /[[:digit:][:^xdigit:]]/ # 'a' から 'f' と 'A' から 'F' 以外の任意の文字に
20952433 # マッチング。これはメインの文字クラスでは二つの
20962434 # POSIX 文字クラスが OR され、一つは任意の数字に
20972435 # マッチングし、もう一つは 16 進文字でない全ての
20982436 # 文字にマッチングします。OR は数字を加え、
20992437 # 'a' から 'f' および 'A' から 'F' のみが
21002438 # 除外されて残ります。
2101 #
21022439
21032440=head3 Extended Bracketed Character Classes
21042441X<character class>
21052442X<set operations>
21062443
21072444(拡張大かっこ文字クラス)
21082445
21092446=begin original
21102447
21112448This is a fancy bracketed character class that can be used for more
21122449readable and less error-prone classes, and to perform set operations,
21132450such as intersection. An example is
21142451
21152452=end original
21162453
21172454これはしゃれた大かっこ文字クラスで、より読みやすく、エラーが発生しにくい
21182455クラスや、交差などの集合演算を実行するために使用できます。
2456例は:
21192457
21202458 /(?[ \p{Thai} & \p{Digit} ])/
21212459
21222460=begin original
21232461
21242462This will match all the digit characters that are in the Thai script.
21252463
21262464=end original
21272465
21282466これは、タイ語スクリプト内のすべての数字と一致します。
21292467
21302468=begin original
21312469
2132This is an experimental feature available starting in 5.18, and is
2470This feature became available in Perl 5.18, as experimental; accepted in
2133subject to change as we gain field experience with it. Any attempt to
24715.36.
2134use it will raise a warning, unless disabled via
21352472
21362473=end original
21372474
2138は 5.18 から利用きる実験的な機で、現場での経験を積むつれて
2475の機能Perl 5.18 で実験的に利用可能になりました;
2139変更さる可能性があり
24765.36 で受け入られした
2140これを使用しようとすると、次のようにして無効にしない限り、警告が表示されます:
21412477
2142 no warnings "experimental::regex_sets";
2143
21442478=begin original
21452479
2146Comments on this feature are welcome; send email to
2480The rules used by L<C<use re 'strict>|re/'strict' mode> apply to this
2147C<perl5-porters@perl.org>.
2481construct.
21482482
21492483=end original
21502484
2151この機能関するコメントを歓迎します。
2485L<C<use re 'strict>|re/'strict' mode> で使われる規則はこの構文
2152C<perl5-porters@perl.org> に電子メールを送ってくだ
2486適用れます
21532487
21542488=begin original
21552489
21562490We can extend the example above:
21572491
21582492=end original
21592493
21602494上記の例を拡張できます:
21612495
21622496 /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/
21632497
21642498=begin original
21652499
21662500This matches digits that are in either the Thai or Laotian scripts.
21672501
21682502=end original
21692503
21702504これはタイ語またはラオス語のいずれかの数字と一致します。
21712505
21722506=begin original
21732507
21742508Notice the white space in these examples. This construct always has
2175the C<E<sol>x> modifier turned on.
2509the C<E<sol>xx> modifier turned on within it.
21762510
21772511=end original
21782512
21792513これらの例の中の空白に注意してください。
2180この構文では、常に C<E<sol>x> 修飾子がオンになっています。
2514この構文では、その中では常に C<E<sol>xx> 修飾子がオンになっています。
21812515
21822516=begin original
21832517
21842518The available binary operators are:
21852519
21862520=end original
21872521
21882522使用可能な 2 項演算子は次のとおりです:
21892523
21902524 & intersection
21912525 + union
21922526 | another name for '+', hence means union
21932527 - subtraction (the result matches the set consisting of those
21942528 code points matched by the first operand, excluding any that
21952529 are also matched by the second operand)
21962530 ^ symmetric difference (the union minus the intersection). This
21972531 is like an exclusive or, in that the result is the set of code
21982532 points that are matched by either, but not both, of the
21992533 operands.
22002534
22012535=begin original
22022536
22032537There is one unary operator:
22042538
22052539=end original
22062540
22072541単項演算子が一つあります。
22082542
22092543 ! complement
22102544
22112545=begin original
22122546
2213All the binary operators left associate, and are of equal precedence.
2547All the binary operators left associate; C<"&"> is higher precedence
2214The unary operator right associates, and has higher precedence. Use
2548than the others, which all have equal precedence. The unary operator
2215parentheses to override the default associations. Some feedback we've
2549right associates, and has highest precedence. Thus this follows the
2216received indicates a desire for intersection to have higher precedence
2550normal Perl precedence rules for logical operators. Use parentheses to
2217than union. This is something that feedback from the field may cause us
2551override the default precedence and associativity.
2218to change in future releases; you may want to parenthesize copiously to
2219avoid such changes affecting your code, until this feature is no longer
2220considered experimental.
22212552
22222553=end original
22232554
2224すべての二項演算子は左結合で、同等の優先順位を持ちます。
2555すべての二項演算子は左結合です; C<"&"> はそ他よりも高い優先順位を持ち
2225単項演算子右結合で、より高い優先順位を持ちます。
2556それ以外同等の優先順位を持ちます。
2226デフォルトの関連付けを上書きするにかっこを使います。
2557単項演算子右結合で、最も高優先順位を持ちます。
2227私たちが受け取たいくつかのフィードバックは交差が結合よりも
2558これは通常の Perl の論理演算子に関する優先順位規則に従います。
2228高い優先順位を持つことを望んでいるこ示しています。
2559デフォルトの優先順位と結合上書きすにはかっこを使います。
2229これは、フィールドからのフィードバックによって、
2230将来のリリースで変更される可能性があるものです;
2231この機能が実験的であるとみなされなくなるまで、コードにそのような変更が
2232影響しないように、かっこをたくさん入れた方がよいでしょう。
22332560
22342561=begin original
22352562
22362563The main restriction is that everything is a metacharacter. Thus,
22372564you cannot refer to single characters by doing something like this:
22382565
22392566=end original
22402567
22412568主な制限は、すべてがメタ文字であるということです。
22422569したがって、以下のようにして単一文字を参照することはできません:
22432570
22442571 /(?[ a + b ])/ # Syntax error!
22452572
22462573=begin original
22472574
22482575The easiest way to specify an individual typable character is to enclose
22492576it in brackets:
22502577
22512578=end original
22522579
22532580タイプ可能な個々の文字を指定する最も簡単な方法は、次のように
22542581かっこで囲むことです:
22552582
22562583 /(?[ [a] + [b] ])/
22572584
22582585=begin original
22592586
22602587(This is the same thing as C<[ab]>.) You could also have said the
22612588equivalent:
22622589
22632590=end original
22642591
22652592(これはC<[ab]>と同じことです)。
22662593同じことを言うこともできます:
22672594
22682595 /(?[[ a b ]])/
22692596
22702597=begin original
22712598
2272(You can, of course, specify single characters by using, C<\x{ }>,
2599(You can, of course, specify single characters by using, C<\x{...}>,
2273C<\N{ }>, etc.)
2600C<\N{...}>, etc.)
22742601
22752602=end original
22762603
2277(もちろん、C<\x{ }> や C<\N{ }> などを使用して 1 文字を
2604(もちろん、C<\x{...}> や C<\N{...}> などを使用して 1 文字を
22782605指定することもできます。)
22792606
22802607=begin original
22812608
22822609This last example shows the use of this construct to specify an ordinary
22832610bracketed character class without additional set operations. Note the
2284white space within it; C<E<sol>x> is turned on even within bracketed
2611white space within it. This is allowed because C<E<sol>xx> is
2285character classes, except you can't have comments inside them. Hence,
2612automatically turned on within this construct.
22862613
22872614=end original
22882615
22892616この最後の例では、この構文を使用して、追加の集合操作なしで
22902617通常の大かっこ文字クラスを指定する方法を示しています。
2291この中に空白があることに注意してください;
2618この中に空白があることに注意してください
2292C<E<sol>x> は、かっで囲まれた字クラス内で有効になますが、
2619C<E<sol>xx> は、この構自動的に有効になるのでこれが許されます
2293コメントを含めることはできません。
2294したがって:
22952620
2296 (?[ [#] ])
2297
22982621=begin original
22992622
2300matches the literal character "#". To specify a literal white space character,
2301you can escape it with a backslash, like:
2302
2303=end original
2304
2305は、リテラル文字 "#" にマッチングします。
2306リテラル空白文字を指定するには、次のように逆スラッシュでエスケープします:
2307
2308 /(?[ [ a e i o u \ ] ])/
2309
2310=begin original
2311
2312This matches the English vowels plus the SPACE character.
23132623All the other escapes accepted by normal bracketed character classes are
2314accepted here as well; but unrecognized escapes that generate warnings
2624accepted here as well.
2315in normal classes are fatal errors here.
23162625
23172626=end original
23182627
2319これは英語の母音と SPACE 文字に一致します。
23202628通常の大かっこ文字クラスで受け入れられる他のエスケープは
2321すべてここでも受け入れられますが、通常のクラスで警告を生成する
2629すべてここでも受け入れられます
2322認識されないエスケープはここでは致命的なエラーです。
23232630
23242631=begin original
23252632
2326All warnings from these class elements are fatal, as well as some
2633Because this construct compiles under
2327practices that don't currently warn. For example you cannot say
2634L<C<use re 'strict>|re/'strict' mode>, unrecognized escapes that
2635generate warnings in normal classes are fatal errors here, as well as
2636all other warnings from these class elements, as well as some
2637practices that don't currently warn outside C<re 'strict'>. For example
2638you cannot say
23282639
23292640=end original
23302641
2331れらクラス要素からすべて警告は致命的あり
2642この構文は L<C<use re 'strict>|re/'strict' mode> 下でコンパイルされるので、
2332現在警告していないいくつかプラティも同様です
2643通常のクスで警告を生成
2644認識されないエスケープはここでは致命的なエラーです;
2645これらのクラス要素からのその他すべての警告も同様で、
2646C<re 'strict'> の外側では、現在警告していないいくつかのプラクティスも
2647同様です。
23332648例えば次のようにはできません:
23342649
23352650 /(?[ [ \xF ] ])/ # Syntax error!
23362651
23372652=begin original
23382653
23392654You have to have two hex digits after a braceless C<\x> (use a leading
23402655zero to make two). These restrictions are to lower the incidence of
23412656typos causing the class to not match what you thought it would.
23422657
23432658=end original
23442659
23452660中かっこのない C<\x> の後には 2 桁の 16 進数が必要です(2 桁にするには
23462661先頭の 0 を使用します)。
23472662これらの制限は、クラスが想定したものと一致しない原因となる
23482663タイプミスの発生を減らすためです。
23492664
23502665=begin original
23512666
2667If a regular bracketed character class contains a C<\p{}> or C<\P{}> and
2668is matched against a non-Unicode code point, a warning may be
2669raised, as the result is not Unicode-defined. No such warning will come
2670when using this extended form.
2671
2672=end original
2673
2674通常の大かっこ文字クラスに C<\p{}> や C<\P{}> が含まれていて、
2675非 Unicode 符号位置に対してマッチングした場合、
2676結果は Unicode で定義されていないので、警告が発生します。
2677このような警告は、拡張形式を使った場合は発生しません。
2678
2679=begin original
2680
23522681The final difference between regular bracketed character classes and
23532682these, is that it is not possible to get these to match a
23542683multi-character fold. Thus,
23552684
23562685=end original
23572686
23582687通常の大かっこ文字クラスとこれらのクラスの最後の違いは、
23592688これらを複数文字畳み込みにマッチングさせることができないということです。
23602689従って:
23612690
23622691 /(?[ [\xDF] ])/iu
23632692
23642693=begin original
23652694
23662695does not match the string C<ss>.
23672696
23682697=end original
23692698
23702699は文字列 C<ss> と一致しません。
23712700
23722701=begin original
23732702
23742703You don't have to enclose POSIX class names inside double brackets,
23752704hence both of the following work:
23762705
23772706=end original
23782707
23792708POSIX クラス名を二重かっこで囲む必要はありません;
23802709そのため、以下の両方とも動作します:
23812710
23822711 /(?[ [:word:] - [:lower:] ])/
23832712 /(?[ [[:word:]] - [[:lower:]] ])/
23842713
23852714=begin original
23862715
23872716Any contained POSIX character classes, including things like C<\w> and C<\D>
23882717respect the C<E<sol>a> (and C<E<sol>aa>) modifiers.
23892718
23902719=end original
23912720
23922721C<\w> や C<\D> などの POSIX 文字クラスは、C<E<sol>a>
23932722(および C<E<sol>aa> )修飾子を尊重します。
23942723
23952724=begin original
23962725
2397C<< (?[ ]) >> is a regex-compile-time construct. Any attempt to use
2726Note that C<< (?[ ]) >> is a regex-compile-time construct. Any attempt
2398something which isn't knowable at the time the containing regular
2727to use something which isn't knowable at the time the containing regular
23992728expression is compiled is a fatal error. In practice, this means
2400just three limitiations:
2729just three limitations:
24012730
24022731=end original
24032732
2404C<< (?[ ]) >> は コンパイル時正規表現構文で
2733C<< (?[ ]) >> は コンパイル時正規表現構文であることに注意してください
24052734正規表現を含むコンパイル時に未知のものを使用しようとすると、
24062735致命的なエラーになります。
24072736実際には、これは三つの制限を意味します:
24082737
24092738=over 4
24102739
24112740=item 1
24122741
24132742=begin original
24142743
2415This construct cannot be used within the scope of
2744When compiled within the scope of C<use locale> (or the C<E<sol>l> regex
2416C<use locale> (or the C<E<sol>l> regex modifier).
2745modifier), this construct assumes that the execution-time locale will be
2746a UTF-8 one, and the generated pattern always uses Unicode rules. What
2747gets matched or not thus isn't dependent on the actual runtime locale, so
2748tainting is not enabled. But a C<locale> category warning is raised
2749if the runtime locale turns out to not be UTF-8.
24172750
24182751=end original
24192752
2420この構文は、C<use locale> (または C<E<sol>l> 正規表現修飾子)の
2753C<use locale> (または C<E<sol>l> 正規表現修飾子)の
2421スコープ内では使用できません。
2754スコープ内でコンパイルされると、この構文実行時ロケールが
2755UTF-8 のものであることを仮定し、
2756生成されたパターンは常に Unicode の規則を使います。
2757従ってマッチングするかどうかは実際の実行時ロケールには関係なく、
2758汚染チェックモードは有効になりません。
2759しかし、実行時ロケールが UTF-8 以外になると、
2760C<locale> カテゴリの警告が発生します。
24222761
24232762=item 2
24242763
24252764=begin original
24262765
24272766Any
24282767L<user-defined property|perlunicode/"User-Defined Character Properties">
24292768used must be already defined by the time the regular expression is
24302769compiled (but note that this construct can be used instead of such
24312770properties).
24322771
24332772=end original
24342773
24352774使用される
24362775L<ユーザー定義特性|perlunicode/"User-Defined Character Properties"> は、
24372776正規表現がコンパイルされるときにすでに定義されている必要があります
24382777(ただし、このような特性の代わりにこの構文を使用することもできます)。
24392778
24402779=item 3
24412780
24422781=begin original
24432782
24442783A regular expression that otherwise would compile
24452784using C<E<sol>d> rules, and which uses this construct will instead
24462785use C<E<sol>u>. Thus this construct tells Perl that you don't want
24472786C<E<sol>d> rules for the entire regular expression containing it.
24482787
24492788=end original
24502789
24512790C<E<sol>d> 規則を使用してコンパイルされ、この構文を使用する正規表現は、
24522791代わりに C<E<sol>u> を使用します。
24532792したがって、この構文は、C<E<sol>d> 規則が含まれている
24542793正規表現全体に対して C<E<sol>d> 規則が必要ないことを Perl に通知します。
24552794
24562795=back
24572796
24582797=begin original
24592798
2460The C<E<sol>x> processing within this class is an extended form.
2461Besides the characters that are considered white space in normal C</x>
2462processing, there are 5 others, recommended by the Unicode standard:
2463
2464=end original
2465
2466このクラス内の C<E<sol>x> 処理は拡張された形式です。
2467通常の C</x> 処理で空白と見なされる文字の他に、Unicode 標準で
2468推奨されている五つの文字があります:
2469
2470 U+0085 NEXT LINE
2471 U+200E LEFT-TO-RIGHT MARK
2472 U+200F RIGHT-TO-LEFT MARK
2473 U+2028 LINE SEPARATOR
2474 U+2029 PARAGRAPH SEPARATOR
2475
2476=begin original
2477
24782799Note that skipping white space applies only to the interior of this
24792800construct. There must not be any space between any of the characters
24802801that form the initial C<(?[>. Nor may there be space between the
24812802closing C<])> characters.
24822803
24832804=end original
24842805
24852806空白のスキップは、この構造体の内部にのみ適用されることに注意してください。
24862807最初の C<(?[> を形成する文字の間に空白を入れることはできません。
24872808また、終わりの C<])> 文字の間に空白を入れることもできません。
24882809
24892810=begin original
24902811
2491Just as in all regular expressions, the pattern can can be built up by
2812Just as in all regular expressions, the pattern can be built up by
24922813including variables that are interpolated at regex compilation time.
2493Care must be taken to ensure that you are getting what you expect. For
2814But currently each such sub-component should be an already-compiled
2494example:
2815extended bracketed character class.
24952816
24962817=end original
24972818
24982819すべての正規表現と同様に、正規表現コンパイル時に補完される変数を
24992820含めることでパターンを構築できます。
2500期待どおり結果が得られるように注意が必です。
2821しかし、現在所、このような部分素のそれぞれは
2501例えば:
2822すでにコンパイルされた拡張大かっこ文字クラスであるべきです。
25022823
2503 my $thai_or_lao = '\p{Thai} + \p{Lao}';
2824 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
25042825 ...
25052826 qr/(?[ \p{Digit} & $thai_or_lao ])/;
25062827
25072828=begin original
25082829
2509compiles to
2830If you interpolate something else, the pattern may still compile (or it
2831may die), but if it compiles, it very well may not behave as you would
2832expect:
25102833
25112834=end original
25122835
2513これは次のよコンパイルされます:
2836何か違ものを変数展開すると、パターンはやはりコンパイルされます
2837(あるいは die します)が、コンパイルされると、想像しているものと
2838かなり違う振る舞いになるかもしれません:
25142839
2515 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
2840 my $thai_or_lao = '\p{Thai} + \p{Lao}';
2841 qr/(?[ \p{Digit} & $thai_or_lao ])/;
25162842
25172843=begin original
25182844
2519But this does not have the effect that someone reading the code would
2845compiles to
2520likely expect, as the intersection applies just to C<\p{Thai}>,
2521excluding the Laotian. Pitfalls like this can be avoided by
2522parenthesizing the component pieces:
25232846
25242847=end original
25252848
2526しかし、これは、コードを読んでいる人が期待するような効果はありせん;
2849これは次のようにコンパイルされす:
2527なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
2528適用されないからです。
2529このような落とし穴は、コンポーネントをかっこで囲むことで回避できます:
25302850
2531 my $thai_or_lao = '( \p{Thai} + \p{Lao} )';
2851 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
25322852
25332853=begin original
25342854
2535But any modifiers will still apply to all the components:
2855This does not have the effect that someone reading the source code
2856would likely expect, as the intersection applies just to C<\p{Thai}>,
2857excluding the Laotian.
25362858
25372859=end original
25382860
2539ただし、修飾子すべてのンポネントに適用されま:
2861これ、ソースコードを読んでいる人が期待るような効果はありません;
2862なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
2863適用されないからです。
25402864
2541 my $lower = '\p{Lower} + \p{Digit}';
2542 qr/(?[ \p{Greek} & $lower ])/i;
2543
25442865=begin original
25452866
2546matches upper case things. You can avoid surprises by making the
2547components into instances of this construct by compiling them:
2548
2549=end original
2550
2551これは大文字のものと一致します。
2552コンポーネントをコンパイルしてこの構文の実体にすることで、
2553予期せぬ事態を避けることができます:
2554
2555 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2556 my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
2557
2558=begin original
2559
2560When these are embedded in another pattern, what they match does not
2561change, regardless of parenthesization or what modifiers are in effect
2562in that outer pattern.
2563
2564=end original
2565
2566これらが別のパターンに埋め込まれている場合、親子関係やその外側のパターンで
2567有効な修飾子に関係なく、一致するものは変わりません。
2568
2569=begin original
2570
25712867Due to the way that Perl parses things, your parentheses and brackets
25722868may need to be balanced, even including comments. If you run into any
2573examples, please send them to C<perlbug@perl.org>, so that we can have a
2869examples, please submit them to L<https://github.com/Perl/perl5/issues>,
2574concrete example for this man page.
2870so that we can have a concrete example for this man page.
25752871
25762872=end original
25772873
25782874Perl の構文解析方法によっては、コメントを含めてもかっこと大かっこの
25792875バランスを取る必要がある場合があります。
2580もし何か例を見つけたら、C<perlbug@perl.org> まで送ってください。
2876もし何か例を見つけたら、L<https://github.com/Perl/perl5/issues>
2877登録してください;
25812878そうすれば、この man ページの具体的な例を得ることができます。
2582
2583=begin original
2584
2585We may change it so that things that remain legal uses in normal bracketed
2586character classes might become illegal within this experimental
2587construct. One proposal, for example, is to forbid adjacent uses of the
2588same character, as in C<(?[ [aa] ])>. The motivation for such a change
2589is that this usage is likely a typo, as the second "a" adds nothing.
2590
2591=end original
2592
2593たとえば、C<(?[ [aa] ])> のように、同じ文字を隣接して使用すること
2594を禁止することが提案されています。
2595このような変更の動機は、2 番目の "a" は何も追加しないので、この使用は
2596タイプミスである可能性が高いということです。
25972879
25982880=begin meta
25992881
26002882Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1-)
26012883Status: completed
26022884
26032885=end meta