perlrecharclass > 5.30.0 との差分

perlrecharclass 5.30.0 と 5.26.1 の差分

11
22=encoding euc-jp
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
7676add matching the newline by using the I<single line> modifier:
7777for the entire regular expression with the C</s> modifier, or
7878locally with C<(?s)> (and even globally within the scope of
7979L<C<use re '/s'>|re/'E<sol>flags' mode>). (The C<L</\N>> backslash
8080sequence, described
8181below, matches any character except newline without regard to the
8282I<single line> modifier.)
8383
8484=end original
8585
8686ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に
8787もっともよく知られている文字クラスです。
8888デフォルトでは、ドットは改行を除く任意の文字にマッチングします。
8989このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
9090変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには
9191C<(?s)> を使います
9292(そしてグローバルに L<C<use re '/s'>|re/'E<sol>flags' mode> の
9393スコープ内の場合でもそうです)。
9494(後述する C<L</\N>> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
9595関わりなく改行以外の任意の文字にマッチングします。)
9696
9797=begin original
9898
9999Here are some examples:
100100
101101=end original
102102
103103以下は例です:
104104
105105=begin original
106106
107107 "a" =~ /./ # Match
108108 "." =~ /./ # Match
109109 "" =~ /./ # No match (dot has to match a character)
110110 "\n" =~ /./ # No match (dot does not match a newline)
111111 "\n" =~ /./s # Match (global 'single line' modifier)
112112 "\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
113113 "ab" =~ /^.$/ # No match (dot matches one character)
114114
115115=end original
116116
117117 "a" =~ /./ # マッチングする
118118 "." =~ /./ # マッチングする
119119 "" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
120120 "\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
121121 "\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
122122 "\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
123123 "ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
124124
125125=head2 Backslash sequences
126126X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
127127X<\N> X<\v> X<\V> X<\h> X<\H>
128128X<word> X<whitespace>
129129
130130(逆スラッシュシーケンス)
131131
132132=begin original
133133
134134A backslash sequence is a sequence of characters, the first one of which is a
135135backslash. Perl ascribes special meaning to many such sequences, and some of
136136these are character classes. That is, they match a single character each,
137137provided that the character belongs to the specific set of characters defined
138138by the sequence.
139139
140140=end original
141141
142142逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。
143143Perl はそのような並びの多くに特別な意味を持たせていて、
144144その一部は文字クラスです。
145145つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に
146146帰属する一文字にマッチングします。
147147
148148=begin original
149149
150150Here's a list of the backslash sequences that are character classes. They
151151are discussed in more detail below. (For the backslash sequences that aren't
152152character classes, see L<perlrebackslash>.)
153153
154154=end original
155155
156156以下は文字クラスの逆スラッシュシーケンスの一覧です。
157157以下でさらに詳細に議論します。
158158(文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を
159159参照してください。)
160160
161161=begin original
162162
163163 \d Match a decimal digit character.
164164 \D Match a non-decimal-digit character.
165165 \w Match a "word" character.
166166 \W Match a non-"word" character.
167167 \s Match a whitespace character.
168168 \S Match a non-whitespace character.
169169 \h Match a horizontal whitespace character.
170170 \H Match a character that isn't horizontal whitespace.
171171 \v Match a vertical whitespace character.
172172 \V Match a character that isn't vertical whitespace.
173173 \N Match a character that isn't a newline.
174174 \pP, \p{Prop} Match a character that has the given Unicode property.
175175 \PP, \P{Prop} Match a character that doesn't have the Unicode property
176176
177177=end original
178178
179179 \d 10 進数字にマッチング。
180180 \D 非 10 進数字にマッチング。
181181 \w 「単語」文字にマッチング。
182182 \W 非「単語」文字にマッチング。
183183 \s 空白文字にマッチング。
184184 \S 非空白文字にマッチング。
185185 \h 水平空白文字にマッチング。
186186 \H 水平空白でない文字にマッチング。
187187 \v 垂直空白文字にマッチング。
188188 \V 垂直空白でない文字にマッチング。
189189 \N 改行以外の文字にマッチング。
190190 \pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
191191 \PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
192192
193193=head3 \N
194194
195195=begin original
196196
197197C<\N>, available starting in v5.12, like the dot, matches any
198198character that is not a newline. The difference is that C<\N> is not influenced
199199by the I<single line> regular expression modifier (see L</The dot> above). Note
200200that the form C<\N{...}> may mean something completely different. When the
201201C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
202202character that many times. For example, C<\N{3}> means to match 3
203203non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}>
204204is not a legal quantifier, it is presumed to be a named character. See
205205L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and
206206C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
207207names are respectively C<COLON>, C<4F>, and C<F4>.
208208
209209=end original
210210
211211v5.12 から利用可能な C<\N> は、ドットのように、
212212改行以外の任意の文字にマッチングします。
213213違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです
214214(上述の L</The dot> 参照)。
215215C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに
216216注意してください。
217217C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の
218218非改行文字にマッチングします。
219219例えば、C<\N{3}> は三つの非改行にマッチングします;
220220C<\N{5,}> は五つ以上の非改行にマッチングします。
221221しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と
222222推定されます。
223223これについては L<charnames> を参照してください。
224224例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な
225225量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の
226226文字を探そうとします。
227227
228228=head3 Digits
229229
230230(数字)
231231
232232=begin original
233233
234234C<\d> matches a single character considered to be a decimal I<digit>.
235235If the C</a> regular expression modifier is in effect, it matches [0-9].
236236Otherwise, it
237237matches anything that is matched by C<\p{Digit}>, which includes [0-9].
238238(An unlikely possible exception is that under locale matching rules, the
239239current locale might not have C<[0-9]> matched by C<\d>, and/or might match
240240other characters whose code point is less than 256. The only such locale
241241definitions that are legal would be to match C<[0-9]> plus another set of
24224210 consecutive digit characters; anything else would be in violation of
243243the C language standard, but Perl doesn't currently assume anything in
244244regard to this.)
245245
246246=end original
247247
248248C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。
249249C</a> 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。
250250さもなければ、これは C<[0-9]> を含む、C<\p{Digit}> にマッチングするものに
251251マッチングします。
252252(ありそうもない例外はロケールマッチングの下で、現在のロケールが
253253C<\d> にマッチングする [0-9] がないか、
254254符号位置が 256 未満の他の文字にマッチングすることです。
255255唯一正当なロケール定義は、C<[0-9]> に加えてもう一つの 10 の連続した
256256数字の集合にマッチングするもので、
257257それ以外は C 言語標準に違反していますが、
258258Perl は今のところこれに関して何も仮定しません。)
259259
260260=begin original
261261
262262What this means is that unless the C</a> modifier is in effect C<\d> not
263263only matches the digits '0' - '9', but also Arabic, Devanagari, and
264264digits from other languages. This may cause some confusion, and some
265265security issues.
266266
267267=end original
268268
269269これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字
270270'0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の
271271数字もマッチングします。
272272これは混乱やセキュリティ問題を引き起こすことがあります。
273273
274274=begin original
275275
276276Some digits that C<\d> matches look like some of the [0-9] ones, but
277277have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks
278very much like an ASCII DIGIT EIGHT (U+0038), and LEPCHA DIGIT SIX
278very much like an ASCII DIGIT EIGHT (U+0038). An application that
279(U+1C46) looks very much like an ASCII DIGIT FIVE (U+0035). An
280application that
281279is expecting only the ASCII digits might be misled, or if the match is
282280C<\d+>, the matched string might contain a mixture of digits from
283281different writing systems that look like they signify a number different
284282than they actually do. L<Unicode::UCD/num()> can
285283be used to safely
286284calculate the value, returning C<undef> if the input string contains
287such a mixture. Otherwise, for example, a displayed price might be
285such a mixture.
288deliberately different than it appears.
289286
290287=end original
291288
292289C<\d> にマッチングする数字には、[0-9] のように見えるけれども、
293290異なる値を持つものもあります。
294例えば、 C<BENGALI DIGIT FOUR> (U+09EA) は C<ASCII DIGIT EIGHT> (U+0038)
291例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038)
295とてもよく似ていて、
296C<LEPCHA DIGIT SIX> (U+1C46) は C<ASCII DIGIT FIVE> (U+0035) に
297292とてもよく似ています。
298293ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、
299294マッチングが C<\d+> の場合、
300295マッチングした文字列は、実際と異なる値を示しているように見える、
301296異なった書記体系からの数字が混ざったものかもしれません。
302297L<Unicode::UCD/num()> は値を安全に計算するのに使えます;
303298入力文字列がこのような混合を含んでいる場合は C<undef> を返します。
304さもなければ、例えば、表示された価格は見た目と意図的に違うものに
305なるかもしれません。
306299
307300=begin original
308301
309302What C<\p{Digit}> means (and hence C<\d> except under the C</a>
310303modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
311304C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this
312305is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
313306But Unicode also has a different property with a similar name,
314307C<\p{Numeric_Type=Digit}>, which matches a completely different set of
315308characters. These characters are things such as C<CIRCLED DIGIT ONE>
316309or subscripts, or are from writing systems that lack all ten digits.
317310
318311=end original
319312
320313C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、
321314C<\p{General_Category=Decimal_Number}>、または同義語として
322315C<\p{General_Category=Digit}> です。
323316Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に
324317マッチングする文字集合と同じです。
325318ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ
326319別の特性もあります; これは完全に異なる文字集合とマッチングします。
327320これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、
32832110 の数字すべてが揃っていない書記体系からのものです。
329322
330323=begin original
331324
332325The design intent is for C<\d> to exactly match the set of characters
333326that can safely be used with "normal" big-endian positional decimal
334327syntax, where, for example 123 means one 'hundred', plus two 'tens',
335328plus three 'ones'. This positional notation does not necessarily apply
336329to characters that match the other type of "digit",
337330C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
338331
339332=end original
340333
341334設計意図は、C<\d> が「通常の」ビッグエンディアンの
342335位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を
343336加えたものを意味する) で安全に使用できる文字集合と
344337正確にマッチングするようにすることです;
345338この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に
346339マッチングする文字には必ずしも適用されないため、
347340C<\d> はこれらの文字にマッチングしません。
348341
349342=begin original
350343
351344The Tamil digits (U+0BE6 - U+0BEF) can also legally be
352345used in old-style Tamil numbers in which they would appear no more than
353346one in a row, separated by characters that mean "times 10", "times 100",
354347etc. (See L<http://www.unicode.org/notes/tn21>.)
355348
356349=end original
357350
358351タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の
359352数字でも合法的に使用することができます;
360353この数字は、「×10」や「×100」などを意味する文字で区切られて、
3613541 回に一度にしか現れません。
362355(L<http://www.unicode.org/notes/tn21>を参照してください)。
363356
364357=begin original
365358
366359Any character not matched by C<\d> is matched by C<\D>.
367360
368361=end original
369362
370363C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。
371364
372365=head3 Word characters
373366
374367(単語文字)
375368
376369=begin original
377370
378371A C<\w> matches a single alphanumeric character (an alphabetic character, or a
379372decimal digit); or a connecting punctuation character, such as an
380373underscore ("_"); or a "mark" character (like some sort of accent) that
381374attaches to one of those. It does not match a whole word. To match a
382375whole word, use C<\w+>. This isn't the same thing as matching an
383376English word, but in the ASCII range it is the same as a string of
384377Perl-identifier characters.
385378
386379=end original
387380
388381C<\w> は単語全体ではなく、単一の英数字(つまり英字または数字)または
389382下線(C<_>) のような接続句読点
390383またはこれらの一つに付いている(ある種のアクセントのような)「マーク」文字に
391384マッチングします。
392385これは単語全体にはマッチングしません。
393386単語全体にマッチングするには、C<\w+> を使ってください。
394387これは英語の単語にマッチングするのと同じことではありませんが、
395388ASCII の範囲では、Perl の識別子文字の文字列と同じです。
396389
397390=over
398391
399392=item If the C</a> modifier is in effect ...
400393
401394(C</a> 修飾子が有効なら ...)
402395
403396=begin original
404397
405398C<\w> matches the 63 characters [a-zA-Z0-9_].
406399
407400=end original
408401
409402C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。
410403
411404=item otherwise ...
412405
413406(さもなければ ...)
414407
415408=over
416409
417410=item For code points above 255 ...
418411
419412(256 以上の符号位置では ...)
420413
421414=begin original
422415
423416C<\w> matches the same as C<\p{Word}> matches in this range. That is,
424417it matches Thai letters, Greek letters, etc. This includes connector
425418punctuation (like the underscore) which connect two words together, or
426419diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
427420are generally used to add auxiliary markings to letters.
428421
429422=end original
430423
431424C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに
432425マッチングします。
433426つまり、タイ文字、ギリシャ文字などです。
434427これには(下線のような)二つの単語を繋ぐ接続句読点、
435428C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために
436429使われる修飾字のようなダイアクリティカルマークが含まれます。
437430
438431=item For code points below 256 ...
439432
440433(255 以下の符号位置では ...)
441434
442435=over
443436
444437=item if locale rules are in effect ...
445438
446439(ロケール規則が有効なら ...)
447440
448441=begin original
449442
450443C<\w> matches the platform's native underscore character plus whatever
451444the locale considers to be alphanumeric.
452445
453446=end original
454447
455448C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と
456449考えるものにマッチングします。
457450
458451=item if, instead, Unicode rules are in effect ...
459452
460453(そうではなく、Unicode 規則が有効なら ...)
461454
462455=begin original
463456
464457C<\w> matches exactly what C<\p{Word}> matches.
465458
466459=end original
467460
468461C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。
469462
470463=item otherwise ...
471464
472465(さもなければ ...)
473466
474467=begin original
475468
476469C<\w> matches [a-zA-Z0-9_].
477470
478471=end original
479472
480473C<\w> は [a-zA-Z0-9_] にマッチングします。
481474
482475=back
483476
484477=back
485478
486479=back
487480
488481=begin original
489482
490483Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
491484
492485=end original
493486
494487どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
495488記述されている方法で決定されます。
496489
497490=begin original
498491
499492There are a number of security issues with the full Unicode list of word
500493characters. See L<http://unicode.org/reports/tr36>.
501494
502495=end original
503496
504497完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。
505498L<http://unicode.org/reports/tr36> を参照してください。
506499
507500=begin original
508501
509502Also, for a somewhat finer-grained set of characters that are in programming
510503language identifiers beyond the ASCII range, you may wish to instead use the
511504more customized L</Unicode Properties>, C<\p{ID_Start}>,
512505C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See
513506L<http://unicode.org/reports/tr31>.
514507
515508=end original
516509
517510また、ASCII の範囲を超えたプログラミング言語識別子のための
518511より高精度の文字集合のためには、代わりによりカスタマイズされた
519512L<Unicode 特性|/Unicode Properties>である
520513 C<\p{ID_Start}>,
521514C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を
522515使った方がよいでしょう。
523516L<http://unicode.org/reports/tr31> を参照してください。
524517
525518=begin original
526519
527520Any character not matched by C<\w> is matched by C<\W>.
528521
529522=end original
530523
531524C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。
532525
533526=head3 Whitespace
534527
535528(空白)
536529
537530=begin original
538531
539532C<\s> matches any single character considered whitespace.
540533
541534=end original
542535
543536C<\s> は空白と考えられる単一の文字にマッチングします。
544537
545538=over
546539
547540=item If the C</a> modifier is in effect ...
548541
549542(C</a> 修飾子が有効なら ...)
550543
551544=begin original
552545
553546In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that
554547is, the horizontal tab,
555548the newline, the form feed, the carriage return, and the space.
556549Starting in Perl v5.18, it also matches the vertical tab, C<\cK>.
557550See note C<[1]> below for a discussion of this.
558551
559552=end original
560553
561554全ての Perl バージョンで、C<\s> は [\t\n\f\r ] の 5 文字にマッチングします;
562555つまり、水平タブ、改行、改頁、復帰、スペースです。
563556Perl 5.18 から、垂直タブ C<\cK> にもマッチングします。
564557ここでの議論については後述する C<[1]> を参照してください。
565558
566559=item otherwise ...
567560
568561(さもなければ ...)
569562
570563=over
571564
572565=item For code points above 255 ...
573566
574567(256 以上の符号位置では ...)
575568
576569=begin original
577570
578571C<\s> matches exactly the code points above 255 shown with an "s" column
579572in the table below.
580573
581574=end original
582575
583576C<\s> は、後述する表の "s" の列で示されている、
584577255 を超える符号位置に正確にマッチングします。
585578
586579=item For code points below 256 ...
587580
588581(255 以下の符号位置では ...)
589582
590583=over
591584
592585=item if locale rules are in effect ...
593586
594587(ロケール規則が有効なら ...)
595588
596589=begin original
597590
598591C<\s> matches whatever the locale considers to be whitespace.
599592
600593=end original
601594
602595C<\s> はロケールが空白だと考えるものにマッチングします。
603596
604597=item if, instead, Unicode rules are in effect ...
605598
606599(そうではなく、Unicode 規則が有効なら ...)
607600
608601=begin original
609602
610603C<\s> matches exactly the characters shown with an "s" column in the
611604table below.
612605
613606=end original
614607
615608C<\s> は正確に以下の表で "s" の列にある文字にマッチングします。
616609
617610=item otherwise ...
618611
619612(さもなければ ...)
620613
621614=begin original
622615
623616C<\s> matches [\t\n\f\r ] and, starting in Perl
624617v5.18, the vertical tab, C<\cK>.
625618(See note C<[1]> below for a discussion of this.)
626619Note that this list doesn't include the non-breaking space.
627620
628621=end original
629622
630623C<\s> は [\t\n\f\r ] にマッチングし、Perl v5.18 から、
631624垂直タブ C<\cK> にもマッチングします。
632625(これの議論については後述する C<[1]> を参照してください。)
633626この一覧にはノーブレークスペースが含まれていないことに注意してください。
634627
635628=back
636629
637630=back
638631
639632=back
640633
641634=begin original
642635
643636Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
644637
645638=end original
646639
647640どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
648641記述されている方法で決定されます。
649642
650643=begin original
651644
652645Any character not matched by C<\s> is matched by C<\S>.
653646
654647=end original
655648
656649C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。
657650
658651=begin original
659652
660653C<\h> matches any character considered horizontal whitespace;
661654this includes the platform's space and tab characters and several others
662655listed in the table below. C<\H> matches any character
663656not considered horizontal whitespace. They use the platform's native
664657character set, and do not consider any locale that may otherwise be in
665658use.
666659
667660=end original
668661
669662C<\h> は水平空白と考えられる任意の文字にマッチングします; これは
670663プラットフォームのスペースとタブ文字および以下の表に上げられている
671664いくつかのその他の文字です。
672665C<\H> は水平空白と考えられない文字にマッチングします。
673666これらはプラットフォームのネイティブな文字集合を使い、
674667他の場所では有効なロケールを考慮しません。
675668
676669=begin original
677670
678671C<\v> matches any character considered vertical whitespace;
679672this includes the platform's carriage return and line feed characters (newline)
680673plus several other characters, all listed in the table below.
681674C<\V> matches any character not considered vertical whitespace.
682675They use the platform's native character set, and do not consider any
683676locale that may otherwise be in use.
684677
685678=end original
686679
687680C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは
688681プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です;
689682全ては以下の表に挙げられています。
690683C<\V> は垂直空白と考えられない任意の文字にマッチングします。
691684これらはプラットフォームのネイティブな文字集合を使い、
692685他の場所では有効なロケールを考慮しません。
693686
694687=begin original
695688
696689C<\R> matches anything that can be considered a newline under Unicode
697690rules. It can match a multi-character sequence. It cannot be used inside
698691a bracketed character class; use C<\v> instead (vertical whitespace).
699692It uses the platform's
700693native character set, and does not consider any locale that may
701694otherwise be in use.
702695Details are discussed in L<perlrebackslash>.
703696
704697=end original
705698
706699C<\R> は Unicode の規則で改行と考えられるものにマッチングします。
707700複数文字の並びにマッチングすることもあります。
708701従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を
709702使ってください。
710703これらはプラットフォームのネイティブな文字集合を使い、
711704他の場所では有効なロケールを考慮しません。
712705詳細は L<perlrebackslash> で議論しています。
713706
714707=begin original
715708
716709Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
717710the same characters, without regard to other factors, such as the active
718711locale or whether the source string is in UTF-8 format.
719712
720713=end original
721714
722715C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の
723716ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず
724717同じ文字にマッチングします。
725718
726719=begin original
727720
728721One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true
729722starting in Perl v5.18, but prior to that, the sole difference was that the
730723vertical tab (C<"\cK">) was not matched by C<\s>.
731724
732725=end original
733726
734727C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。
735728Perl 5.18 からはもちろん正しいです; しかしそれより前では、
736729唯一の違いは、垂直タブ (C<"\xcK">) は C<\s> にマッチングしないということです。
737730
738731=begin original
739732
740733The following table is a complete listing of characters matched by
741734C<\s>, C<\h> and C<\v> as of Unicode 6.3.
742735
743736=end original
744737
745738以下の表は Unicode 6.3 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
746739完全な一覧です。
747740
748741=begin original
749742
750743The first column gives the Unicode code point of the character (in hex format),
751744the second column gives the (Unicode) name. The third column indicates
752745by which class(es) the character is matched (assuming no locale is in
753746effect that changes the C<\s> matching).
754747
755748=end original
756749
757750最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の)
758751名前です。
7597523 番目の列はどのクラスにマッチングするかを示しています
760753(C<\s> のマッチングを変更するようなロケールが
761754有効でないことを仮定しています)。
762755
763756 0x0009 CHARACTER TABULATION h s
764757 0x000a LINE FEED (LF) vs
765758 0x000b LINE TABULATION vs [1]
766759 0x000c FORM FEED (FF) vs
767760 0x000d CARRIAGE RETURN (CR) vs
768761 0x0020 SPACE h s
769762 0x0085 NEXT LINE (NEL) vs [2]
770763 0x00a0 NO-BREAK SPACE h s [2]
771764 0x1680 OGHAM SPACE MARK h s
772765 0x2000 EN QUAD h s
773766 0x2001 EM QUAD h s
774767 0x2002 EN SPACE h s
775768 0x2003 EM SPACE h s
776769 0x2004 THREE-PER-EM SPACE h s
777770 0x2005 FOUR-PER-EM SPACE h s
778771 0x2006 SIX-PER-EM SPACE h s
779772 0x2007 FIGURE SPACE h s
780773 0x2008 PUNCTUATION SPACE h s
781774 0x2009 THIN SPACE h s
782775 0x200a HAIR SPACE h s
783776 0x2028 LINE SEPARATOR vs
784777 0x2029 PARAGRAPH SEPARATOR vs
785778 0x202f NARROW NO-BREAK SPACE h s
786779 0x205f MEDIUM MATHEMATICAL SPACE h s
787780 0x3000 IDEOGRAPHIC SPACE h s
788781
789782=over 4
790783
791784=item [1]
792785
793786=begin original
794787
795788Prior to Perl v5.18, C<\s> did not match the vertical tab.
796789C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did.
797790
798791=end original
799792
800793Perl v5.18 より前では、C<\s> は垂直タブにマッチングしませんでした。
801794C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的に
802795マッチングしていたものにマッチングします。
803796
804797=item [2]
805798
806799=begin original
807800
808801NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
809802on the rules in effect. See
810803L<the beginning of this section|/Whitespace>.
811804
812805=end original
813806
814807NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に
815808マッチングしたりマッチングしなかったりします。
816809L<the beginning of this section|/Whitespace> を参照してください。
817810
818811=back
819812
820813=head3 Unicode Properties
821814
822815(Unicode 特性)
823816
824817=begin original
825818
826819C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
827820Unicode properties. One letter property names can be used in the C<\pP> form,
828821with the property name following the C<\p>, otherwise, braces are required.
829822When using braces, there is a single form, which is just the property name
830823enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
831824which means to match if the property "name" for the character has that particular
832825"value".
833826For instance, a match for a number can be written as C</\pN/> or as
834827C</\p{Number}/>, or as C</\p{Number=True}/>.
835828Lowercase letters are matched by the property I<Lowercase_Letter> which
836829has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
837830C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
838831(the underscores are optional).
839832C</\pLl/> is valid, but means something different.
840833It matches a two character string: a letter (Unicode property C<\pL>),
841834followed by a lowercase C<l>.
842835
843836=end original
844837
845838C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に
846839マッチングする文字クラスです。
847840一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ
848841中かっこが必要です。
849842中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、
850843C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を
851844持つものにマッチングすることになる複合形式があります。
852845例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または
853846C</\p{Number=True}/> と書けます。
854847小文字は I<LowercaseLetter> 特性にマッチングします; これには
855848I<Ll> と言う短縮形式があります。
856849中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または
857850C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。
858851C</\pLl/> も妥当ですが、違う意味になります。
859852これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて
860853小文字の C<l> です。
861854
862855=begin original
863856
864What a Unicode property matches is never subject to locale rules, and
857If locale rules are not in effect, the use of
865if locale rules are not otherwise in effect, the use of a Unicode
858a Unicode property will force the regular expression into using Unicode
866property will force the regular expression into using Unicode rules, if
859rules, if it isn't already.
867it isn't already.
868860
869861=end original
870862
871Unicode 特性が何にマッチングするかは決してロケールの規則に影響されず、
872863ロケール規則が有効でない場合、Unicode 特性を使うと
873864正規表現に (まだそうでなければ) Unicode 規則を使うように強制します。
874865
875866=begin original
876867
877868Note that almost all properties are immune to case-insensitive matching.
878869That is, adding a C</i> regular expression modifier does not change what
879870they match. There are two sets that are affected. The first set is
880871C<Uppercase_Letter>,
881872C<Lowercase_Letter>,
882873and C<Titlecase_Letter>,
883874all of which match C<Cased_Letter> under C</i> matching.
884875The second set is
885876C<Uppercase>,
886877C<Lowercase>,
887878and C<Titlecase>,
888879all of which match C<Cased> under C</i> matching.
889880(The difference between these sets is that some things, such as Roman
890881numerals, come in both upper and lower case, so they are C<Cased>, but
891882aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
892883actually C<Letter_Number>s.)
893884This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
894885of which under C</i> match C<PosixAlpha>.
895886
896887=end original
897888
898889ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに
899890注意してください。
900891つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を
901892与えないということです。
902893影響を与える二つの集合があります。
903894一つ目の集合は
904895C<Uppercase_Letter>,
905896C<Lowercase_Letter>,
906897C<Titlecase_Letter> で、全て C</i> マッチングの下で
907898C<Cased_Letter> にマッチングします。
908899二つ目の集合は
909900C<Uppercase>,
910901C<Lowercase>,
911902C<Titlecase> で、全てC</i> マッチングの下で
912903C<Cased> にマッチングします。
913904(これらの集合の違いは、ローマ数字のような一部のものは、
914905大文字と小文字があるので C<Cased> ですが、
915906文字とは扱われないので C<Cased_Letter> ではありません。
916907これらは実際には C<Letter_Number> です。)
917908この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます;
918909これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。
919910
920911=begin original
921912
922913For more details on Unicode properties, see L<perlunicode/Unicode
923914Character Properties>; for a
924915complete list of possible properties, see
925916L<perluniprops/Properties accessible through \p{} and \P{}>,
926917which notes all forms that have C</i> differences.
927918It is also possible to define your own properties. This is discussed in
928919L<perlunicode/User-Defined Character Properties>.
929920
930921=end original
931922
932923Unicode 特性に関するさらなる詳細については、
933924L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な
934925一覧については、C</i> に違いのある全ての形式について記されている
935926L<perluniprops/Properties accessible through \p{} and \P{}> を参照して
936927ください。
937928独自の特性を定義することも可能です。
938929これは L<perlunicode/User-Defined Character Properties> で
939930議論されています。
940931
941932=begin original
942933
943934Unicode properties are defined (surprise!) only on Unicode code points.
944935Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats
945936non-Unicode code points (those above the legal Unicode maximum of
9469370x10FFFF) as if they were typical unassigned Unicode code points.
947938
948939=end original
949940
950941Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ
951942定義されています。
952943v5.20 から、C<\p> と C<\P> に対してマッチングするとき、
953944Perl は
954945非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) を、
955946典型的な未割り当て Unicode 符号位置であるかのように扱います。
956947
957948=begin original
958949
959950Prior to v5.20, Perl raised a warning and made all matches fail on
960951non-Unicode code points. This could be somewhat surprising:
961952
962953=end original
963954
964955v5.20 より前では、非 Unicode 符号位置に対しては全てのマッチングは失敗して、
965956Perl は警告を出していました。
966957これは驚かされるものだったかもしれません。
967958
968959 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails on Perls < v5.20.
969960 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails on Perls
970961 # < v5.20
971962
972963=begin original
973964
974965Even though these two matches might be thought of as complements, until
975966v5.20 they were so only on Unicode code points.
976967
977968=end original
978969
979970これら二つのマッチングは補集合と考えるかもしれませんが、
980971v5.20 まで、これらは Unicode 符号位置だけでした。
981972
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
992973=head4 Examples
993974
994975(例)
995976
996977=begin original
997978
998979 "a" =~ /\w/ # Match, "a" is a 'word' character.
999980 "7" =~ /\w/ # Match, "7" is a 'word' character as well.
1000981 "a" =~ /\d/ # No match, "a" isn't a digit.
1001982 "7" =~ /\d/ # Match, "7" is a digit.
1002983 " " =~ /\s/ # Match, a space is whitespace.
1003984 "a" =~ /\D/ # Match, "a" is a non-digit.
1004985 "7" =~ /\D/ # No match, "7" is not a non-digit.
1005986 " " =~ /\S/ # No match, a space is not non-whitespace.
1006987
1007988=end original
1008989
1009990 "a" =~ /\w/ # マッチング; "a" は「単語」文字。
1010991 "7" =~ /\w/ # マッチング; "7" も「単語」文字。
1011992 "a" =~ /\d/ # マッチングしない; "a" は数字ではない。
1012993 "7" =~ /\d/ # マッチング; "7" は数字。
1013994 " " =~ /\s/ # マッチング; スペースは空白。
1014995 "a" =~ /\D/ # マッチング; "a" は非数字。
1015996 "7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
1016997 " " =~ /\S/ # マッチングしない; スペースは非空白ではない。
1017998
1018999=begin original
10191000
10201001 " " =~ /\h/ # Match, space is horizontal whitespace.
10211002 " " =~ /\v/ # No match, space is not vertical whitespace.
10221003 "\r" =~ /\v/ # Match, a return is vertical whitespace.
10231004
10241005=end original
10251006
10261007 " " =~ /\h/ # マッチング; スペースは水平空白。
10271008 " " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
10281009 "\r" =~ /\v/ # マッチング; 復帰は垂直空白。
10291010
10301011=begin original
10311012
10321013 "a" =~ /\pL/ # Match, "a" is a letter.
10331014 "a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.
10341015
10351016=end original
10361017
10371018 "a" =~ /\pL/ # マッチング; "a" は英字。
10381019 "a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。
10391020
10401021=begin original
10411022
10421023 "\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character
10431024 # 'THAI CHARACTER SO SO', and that's in
10441025 # Thai Unicode class.
10451026 "a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character.
10461027
10471028=end original
10481029
10491030 "\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字
10501031 # 'THAI CHARACTER SO SO' で、これは
10511032 # Thai Unicode クラスにある。
10521033 "a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。
10531034
10541035=begin original
10551036
10561037It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
10571038complete numbers or words. To match a number (that consists of digits),
10581039use C<\d+>; to match a word, use C<\w+>. But be aware of the security
10591040considerations in doing so, as mentioned above.
10601041
10611042=end original
10621043
10631044C<\d>, C<\w> などは数値や単語全体ではなく、1 文字にマッチングすることは
10641045強調する価値があります。
10651046(数字で構成される) 数値 にマッチングするには C<\d+> を使います;
10661047単語にマッチングするには C<\w+> を使います。
10671048しかし前述したように、そうする場合のセキュリティ問題について
10681049注意してください。
10691050
10701051=head2 Bracketed Character Classes
10711052
10721053(かっこ付き文字クラス)
10731054
10741055=begin original
10751056
10761057The third form of character class you can use in Perl regular expressions
10771058is the bracketed character class. In its simplest form, it lists the characters
10781059that may be matched, surrounded by square brackets, like this: C<[aeiou]>.
10791060This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Like the other
10801061character classes, exactly one character is matched.* To match
10811062a longer string consisting of characters mentioned in the character
10821063class, follow the character class with a L<quantifier|perlre/Quantifiers>. For
10831064instance, C<[aeiou]+> matches one or more lowercase English vowels.
10841065
10851066=end original
10861067
10871068Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ文字クラスです。
10881069もっとも単純な形式では、以下のように大かっこの中にマッチングする文字を
10891070リストします: C<[aeiou]>.
10901071これは C<a>, C<e>, C<i>, C<o>, C<u> のどれかにマッチングします。
10911072他の文字クラスと同様、正確に一つの文字にマッチングします。
10921073文字クラスで言及した文字で構成されるより長い文字列にマッチングするには、
10931074文字クラスに L<量指定子|perlre/Quantifiers> を付けます。
10941075例えば、C<[aeiou]+> は一つまたはそれ以上の小文字英語母音に
10951076マッチングします。
10961077
10971078=begin original
10981079
10991080Repeating a character in a character class has no
11001081effect; it's considered to be in the set only once.
11011082
11021083=end original
11031084
11041085文字クラスの中で文字を繰り返しても効果はありません; 一度だけ現れたものと
11051086考えられます。
11061087
11071088=begin original
11081089
11091090Examples:
11101091
11111092=end original
11121093
11131094例:
11141095
11151096=begin original
11161097
11171098 "e" =~ /[aeiou]/ # Match, as "e" is listed in the class.
11181099 "p" =~ /[aeiou]/ # No match, "p" is not listed in the class.
11191100 "ae" =~ /^[aeiou]$/ # No match, a character class only matches
11201101 # a single character.
11211102 "ae" =~ /^[aeiou]+$/ # Match, due to the quantifier.
11221103
11231104=end original
11241105
11251106 "e" =~ /[aeiou]/ # マッチング; "e" はクラスにある。
11261107 "p" =~ /[aeiou]/ # マッチングしない; "p" はクラスにない。
11271108 "ae" =~ /^[aeiou]$/ # マッチングしない; 一つの文字クラスは
11281109 # 一文字だけにマッチングする。
11291110 "ae" =~ /^[aeiou]+$/ # マッチング; 量指定子により。
11301111
11311112 -------
11321113
11331114=begin original
11341115
11351116* There are two exceptions to a bracketed character class matching a
11361117single character only. Each requires special handling by Perl to make
11371118things work:
11381119
11391120=end original
11401121
11411122* 大かっこ文字クラスは単一の文字にのみマッチングするということには
11421123二つの例外があります。
11431124それぞれは Perl がうまく動くために特別な扱いが必要です:
11441125
11451126=over
11461127
11471128=item *
11481129
11491130=begin original
11501131
11511132When the class is to match caselessly under C</i> matching rules, and a
11521133character that is explicitly mentioned inside the class matches a
11531134multiple-character sequence caselessly under Unicode rules, the class
11541135will also match that sequence. For example, Unicode says that the
11551136letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss>
11561137under C</i> rules. Thus,
11571138
11581139=end original
11591140
11601141クラスが C</i> マッチング規則の下で大文字小文字を無視したマッチングを
11611142して、クラスの中で明示的に記述された文字が Unicode の規則の下で複数文字並びに
11621143大文字小文字を無視してマッチングするとき、
11631144そのクラスはその並びにもマッチングします。
11641145例えば、Unicode は文字 C<LATIN SMALL LETTER SHARP S> は C</i> 規則の下では
11651146並び C<ss> にマッチングするとしています。
11661147従って:
11671148
11681149 'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i # Matches
11691150 'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i # Matches
11701151
11711152=begin original
11721153
11731154For this to happen, the class must not be inverted (see L</Negation>)
11741155and the character must be explicitly specified, and not be part of a
11751156multi-character range (not even as one of its endpoints). (L</Character
11761157Ranges> will be explained shortly.) Therefore,
11771158
11781159=end original
11791160
11801161これが起きるためには、
11811162そのクラスは否定 (L</Negation> 参照) ではなく、
11821163その文字は明示的に指定され、複数文字範囲の一部
11831164(たとえその端でも)でない必要があります。
11841165(L</Character Ranges> は短く説明されています。)
11851166従って:
11861167
11871168 'ss' =~ /\A[\0-\x{ff}]\z/ui # Doesn't match
11881169 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui # No match
11891170 'ss' =~ /\A[\xDF-\xDF]\z/ui # Matches on ASCII platforms, since
11901171 # \xDF is LATIN SMALL LETTER SHARP S,
11911172 # and the range is just a single
11921173 # element
11931174
11941175=begin original
11951176
11961177Note that it isn't a good idea to specify these types of ranges anyway.
11971178
11981179=end original
11991180
12001181どちらにしろこれらの種類の範囲を指定するのは良い考えではありません。
12011182
12021183=item *
12031184
12041185=begin original
12051186
12061187Some names known to C<\N{...}> refer to a sequence of multiple characters,
12071188instead of the usual single character. When one of these is included in
12081189the class, the entire sequence is matched. For example,
12091190
12101191=end original
12111192
12121193Some names known to
12131194C<\N{...}> で知られているいくつかの名前は、通常の単一の文字ではなく、
12141195複数の文字の並びを参照します。
12151196その一つがこのクラスに含まれている場合、並び全体がマッチングします。
12161197例えば:
12171198
12181199 "\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}"
12191200 =~ / ^ [\N{TAMIL SYLLABLE KAU}] $ /x;
12201201
12211202=begin original
12221203
12231204matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence
12241205consisting of the two characters matched against. Like the other
12251206instance where a bracketed class can match multiple characters, and for
12261207similar reasons, the class must not be inverted, and the named sequence
12271208may not appear in a range, even one where it is both endpoints. If
12281209these happen, it is a fatal error if the character class is within the
12291210scope of L<C<use re 'strict>|re/'strict' mode>, or within an extended
12301211L<C<(?[...])>|/Extended Bracketed Character Classes> class; otherwise
12311212only the first code point is used (with a C<regexp>-type warning
12321213raised).
12331214
12341215=end original
12351216
12361217これはマッチングします; なぜなら C<\N{TAMIL SYLLABLE KAU}> は
12371218マッチングする二つの文字からなる名前付き並びだからです。
12381219大かっこクラスが複数の文字にマッチングするその他の例と同じように、
12391220そして同様の理由で、クラスは否定できず、
12401221たとえ両端の間であっても名前付き並びは範囲の中には現れません。
12411222これらが起きたとき、文字クラスが
12421223L<C<use re 'strict>|re/'strict' mode> のスコープ内か、
12431224拡張された L<C<(?[...])>|/Extended Bracketed Character Classes> クラスの
12441225中の場合には致命的エラーになります;
12451226さもなければ、最初の符号位置のみが使われます
12461227(そして C<regexp> 系の警告が発生します)。
12471228
12481229=back
12491230
12501231=head3 Special Characters Inside a Bracketed Character Class
12511232
12521233(かっこ付き文字クラスの中の特殊文字)
12531234
12541235=begin original
12551236
12561237Most characters that are meta characters in regular expressions (that
12571238is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
12581239their special meaning and can be used inside a character class without
12591240the need to escape them. For instance, C<[()]> matches either an opening
12601241parenthesis, or a closing parenthesis, and the parens inside the character
12611242class don't group or capture. Be aware that, unless the pattern is
12621243evaluated in single-quotish context, variable interpolation will take
12631244place before the bracketed class is parsed:
12641245
12651246=end original
12661247
12671248正規表現内でメタ文字(つまり、C<.>, C<*>, C<(> のように特別な意味を持つ
12681249文字)となるほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を
12691250失うので、エスケープする必要はありません。
12701251例えば、C<[()]> は開きかっこまたは閉じかっこにマッチングし、文字クラスの中の
12711252かっこはグループや捕捉にはなりません。
12721253パターンがシングルクォート風コンテキストの中で評価されない限り、
12731254変数展開は大かっこクラスがパースされる前に行われることに注意してください:
12741255
12751256 $, = "\t| ";
12761257 $a =~ m'[$,]'; # single-quotish: matches '$' or ','
12771258 $a =~ q{[$,]}' # same
12781259 $a =~ m/[$,]/; # double-quotish: matches "\t", "|", or " "
12791260
12801261=begin original
12811262
12821263Characters that may carry a special meaning inside a character class are:
12831264C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
12841265escaped with a backslash, although this is sometimes not needed, in which
12851266case the backslash may be omitted.
12861267
12871268=end original
12881269
12891270文字クラスの中でも特別な意味を持つ文字は:
12901271C<\>, C<^>, C<->, C<[>, C<]> で、以下で議論します。
12911272これらは逆スラッシュでエスケープできますが、不要な場合もあり、そのような
12921273場合では逆スラッシュは省略できます。
12931274
12941275=begin original
12951276
12961277The sequence C<\b> is special inside a bracketed character class. While
12971278outside the character class, C<\b> is an assertion indicating a point
12981279that does not have either two word characters or two non-word characters
12991280on either side, inside a bracketed character class, C<\b> matches a
13001281backspace character.
13011282
13021283=end original
13031284
13041285シーケンス C<\b> は大かっこ文字クラスの内側では特別です。
13051286文字クラスの外側では C<\b> 二つの単語文字か二つの非単語文字のどちらかではない
13061287位置を示す表明ですが、大かっこ文字クラスの内側では C<\b> は後退文字に
13071288マッチングします。
13081289
13091290=begin original
13101291
13111292The sequences
13121293C<\a>,
13131294C<\c>,
13141295C<\e>,
13151296C<\f>,
13161297C<\n>,
13171298C<\N{I<NAME>}>,
13181299C<\N{U+I<hex char>}>,
13191300C<\r>,
13201301C<\t>,
13211302and
13221303C<\x>
13231304are also special and have the same meanings as they do outside a
13241305bracketed character class.
13251306
13261307=end original
13271308
13281309並び
13291310C<\a>,
13301311C<\c>,
13311312C<\e>,
13321313C<\f>,
13331314C<\n>,
13341315C<\N{I<NAME>}>,
13351316C<\N{U+I<hex char>}>,
13361317C<\r>,
13371318C<\t>,
13381319C<\x>
13391320も特別で、大かっこ文字クラスの外側と同じ意味を持ちます。
13401321
13411322=begin original
13421323
13431324Also, a backslash followed by two or three octal digits is considered an octal
13441325number.
13451326
13461327=end original
13471328
13481329また、逆スラッシュに引き続いて 2 または 3 桁の 8 進数字があると 8 進数として
13491330扱われます。
13501331
13511332=begin original
13521333
13531334A C<[> is not special inside a character class, unless it's the start of a
13541335POSIX character class (see L</POSIX Character Classes> below). It normally does
13551336not need escaping.
13561337
13571338=end original
13581339
13591340C<[> は、POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
13601341開始でない限りは文字クラスの中では特別ではありません。
13611342これは普通エスケープは不要です。
13621343
13631344=begin original
13641345
13651346A C<]> is normally either the end of a POSIX character class (see
13661347L</POSIX Character Classes> below), or it signals the end of the bracketed
13671348character class. If you want to include a C<]> in the set of characters, you
13681349must generally escape it.
13691350
13701351=end original
13711352
13721353A C<]> は普通は POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
13731354終わりか、大かっこ文字クラスの終了を示すかどちらかです。
13741355文字集合に C<]> を含める必要がある場合、一般的には
13751356エスケープしなければなりません。
13761357
13771358=begin original
13781359
13791360However, if the C<]> is the I<first> (or the second if the first
13801361character is a caret) character of a bracketed character class, it
13811362does not denote the end of the class (as you cannot have an empty class)
13821363and is considered part of the set of characters that can be matched without
13831364escaping.
13841365
13851366=end original
13861367
13871368しかし、C<]> が大かっこ文字クラスの I<最初> (または最初の文字がキャレットなら
138813692 番目) の文字の場合、(空クラスを作ることはできないので)これはクラスの
13891370終了を意味せず、エスケープなしでマッチングできる文字の集合の一部と
13901371考えられます。
13911372
13921373=begin original
13931374
13941375Examples:
13951376
13961377=end original
13971378
13981379例:
13991380
14001381=begin original
14011382
14021383 "+" =~ /[+?*]/ # Match, "+" in a character class is not special.
14031384 "\cH" =~ /[\b]/ # Match, \b inside in a character class
14041385 # is equivalent to a backspace.
14051386 "]" =~ /[][]/ # Match, as the character class contains
14061387 # both [ and ].
14071388 "[]" =~ /[[]]/ # Match, the pattern contains a character class
14081389 # containing just [, and the character class is
14091390 # followed by a ].
14101391
14111392=end original
14121393
14131394 "+" =~ /[+?*]/ # マッチング; 文字クラス内の "+" は特別ではない。
14141395 "\cH" =~ /[\b]/ # マッチング; 文字クラスの内側の \b は後退と
14151396 # 等価。
14161397 "]" =~ /[][]/ # マッチング; 文字クラスに [ と ] の両方を
14171398 # 含んでいる。
14181399 "[]" =~ /[[]]/ # マッチング; パターンは [ だけを含んでいる
14191400 # 文字クラスと、それに引き続く
14201401 # ] からなる。
14211402
14221403=head3 Bracketed Character Classes and the C</xx> pattern modifier
14231404
14241405=begin original
14251406
14261407Normally SPACE and TAB characters have no special meaning inside a
14271408bracketed character class; they are just added to the list of characters
14281409matched by the class. But if the L<C</xx>|perlre/E<sol>x and E<sol>xx>
14291410pattern modifier is in effect, they are generally ignored and can be
14301411added to improve readability. They can't be added in the middle of a
14311412single construct:
14321413
14331414=end original
14341415
14351416通常、大かっこ文字クラスの内側では SPACE と TAB の文字は
14361417特別な意味はありません; これらは単にクラスによってマッチングされる文字の
14371418リストに加えられます。
14381419しかし、L<C</xx>|perlre/E<sol>x and E<sol>xx> パターン修飾子が有効の場合、
14391420これらは一般的に無視されるので、可読性を向上させるために追加できます。
14401421これらは単一の構文の中には追加できません:
14411422
14421423 / [ \x{10 FFFF} ] /xx # WRONG!
14431424
14441425=begin original
14451426
14461427The SPACE in the middle of the hex constant is illegal.
14471428
14481429=end original
14491430
1450143116 進定数の中の SPACE は不正です。
14511432
14521433=begin original
14531434
14541435To specify a literal SPACE character, you can escape it with a
14551436backslash, like:
14561437
14571438=end original
14581439
14591440リテラルな SPACE 文字を指定するには、次のように逆スラッシュで
14601441エスケープします:
14611442
14621443 /[ a e i o u \ ]/xx
14631444
14641445=begin original
14651446
14661447This matches the English vowels plus the SPACE character.
14671448
14681449=end original
14691450
14701451これは英語の母音と SPACE 文字に一致します。
14711452
14721453=begin original
14731454
14741455For clarity, you should already have been using C<\t> to specify a
14751456literal tab, and C<\t> is unaffected by C</xx>.
14761457
14771458=end original
14781459
14791460確認すると、リテラルなタブのためには既に C<\t> を使っているべきで、
14801461C<\t> は C</xx> の影響を受けません。
14811462
14821463=head3 Character Ranges
14831464
14841465(文字範囲)
14851466
14861467=begin original
14871468
14881469It is not uncommon to want to match a range of characters. Luckily, instead
14891470of listing all characters in the range, one may use the hyphen (C<->).
14901471If inside a bracketed character class you have two characters separated
14911472by a hyphen, it's treated as if all characters between the two were in
14921473the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]>
14931474matches any lowercase letter from the first half of the ASCII alphabet.
14941475
14951476=end original
14961477
14971478文字のある範囲にマッチングしたいというのは珍しくありません。
14981479幸運なことに、その範囲の文字を全て一覧に書く代わりに、ハイフン (C<->) を
14991480使えます。
15001481大かっこ文字クラスの内側で二つの文字がハイフンで区切られていると、
15011482二つの文字の間の全ての文字がクラスに書かれているかのように扱われます。
15021483例えば、C<[0-9]> は任意の ASCII 数字にマッチングし、C<[a-m]> は
15031484ASCII アルファベットの前半分の小文字にマッチングします。
15041485
15051486=begin original
15061487
15071488Note that the two characters on either side of the hyphen are not
15081489necessarily both letters or both digits. Any character is possible,
15091490although not advisable. C<['-?]> contains a range of characters, but
15101491most people will not know which characters that means. Furthermore,
15111492such ranges may lead to portability problems if the code has to run on
15121493a platform that uses a different character set, such as EBCDIC.
15131494
15141495=end original
15151496
15161497ハイフンのそれぞれの側の二つの文字は両方とも英字であったり両方とも
15171498数字であったりする必要はないことに注意してください。
15181499任意の文字が可能ですが、勧められません。
15191500C<['-?]> は文字の範囲を含みますが、ほとんどの人はどの文字が含まれるか
15201501分かりません。
15211502さらに、このような範囲は、コードが EBCDIC のような異なった文字集合を使う
15221503プラットフォームで実行されると移植性の問題を引き起こします。
15231504
15241505=begin original
15251506
15261507If a hyphen in a character class cannot syntactically be part of a range, for
15271508instance because it is the first or the last character of the character class,
15281509or if it immediately follows a range, the hyphen isn't special, and so is
15291510considered a character to be matched literally. If you want a hyphen in
15301511your set of characters to be matched and its position in the class is such
15311512that it could be considered part of a range, you must escape that hyphen
15321513with a backslash.
15331514
15341515=end original
15351516
15361517例えば文字クラスの最初または最後であったり、範囲の直後のために、文字クラスの
15371518中のハイフンが文法的に範囲の一部となれない場合、ハイフンは特別ではなく、
15381519リテラルにマッチングするべき文字として扱われます。
15391520マッチングする文字の集合にハイフンを入れたいけれどもその位置が範囲の
15401521一部として考えられる場合はハイフンを逆スラッシュで
15411522エスケープしなければなりません。
15421523
15431524=begin original
15441525
15451526Examples:
15461527
15471528=end original
15481529
15491530例:
15501531
15511532=begin original
15521533
15531534 [a-z] # Matches a character that is a lower case ASCII letter.
15541535 [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or
15551536 # the letter 'z'.
15561537 [-z] # Matches either a hyphen ('-') or the letter 'z'.
15571538 [a-f-m] # Matches any letter between 'a' and 'f' (inclusive), the
15581539 # hyphen ('-'), or the letter 'm'.
15591540 ['-?] # Matches any of the characters '()*+,-./0123456789:;<=>?
15601541 # (But not on an EBCDIC platform).
15611542 [\N{APOSTROPHE}-\N{QUESTION MARK}]
15621543 # Matches any of the characters '()*+,-./0123456789:;<=>?
15631544 # even on an EBCDIC platform.
15641545 [\N{U+27}-\N{U+3F}] # Same. (U+27 is "'", and U+3F is "?")
15651546
15661547=end original
15671548
15681549 [a-z] # 小文字 ASCII 英字にマッチング。
15691550 [a-fz] # 'a' から 'f' の英字およびと 'z' の英字に
15701551 # マッチング。
15711552 [-z] # ハイフン ('-') または英字 'z' にマッチング。
15721553 [a-f-m] # 'a' から 'f' の英字、ハイフン ('-')、英字 'm' に
15731554 # マッチング。
15741555 ['-?] # 文字 '()*+,-./0123456789:;<=>? のどれかにマッチング
15751556 # (しかし EBCDIC プラットフォームでは異なります)。
15761557 [\N{APOSTROPHE}-\N{QUESTION MARK}]
15771558 # たとえ EBCDIC プラットフォームでも '()*+,-./0123456789:;<=>?
15781559 # のいずれかの文字にマッチング。
15791560 [\N{U+27}-\N{U+3F}] # 同じ。 (U+27 は "'", U+3F は "?")
15801561
15811562=begin original
15821563
1583As the final two examples above show, you can achieve portability to
1564As the final two examples above show, you can achieve portablity to
15841565non-ASCII platforms by using the C<\N{...}> form for the range
15851566endpoints. These indicate that the specified range is to be interpreted
15861567using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match
15871568C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>,
15881569and C<\N{U+3F}>, whatever the native code point versions for those are.
15891570These are called "Unicode" ranges. If either end is of the C<\N{...}>
15901571form, the range is considered Unicode. A C<regexp> warning is raised
15911572under C<S<"use re 'strict'">> if the other endpoint is specified
15921573non-portably:
15931574
15941575=end original
15951576
15961577前述の最後の二つの例が示すように、範囲の端点に
15971578C<\N{...}> 形式を使用することで、非 ASCII プラットフォームへの
15981579移植性を実現できます。
15991580これらは、指定された範囲が Unicode 値を使用して解釈されることを示しています;
16001581したがって、C<[\N{U+27}-\N{U+3F}]>は、C<\N{U+27}>、C<\N{U+28}>、
16011582C<\N{U+29}>、...、C<\N{U+3D}>、C<\N{U+3E}>、C<\N{U+3F}> に
16021583マッチングすることを意味します;
16031584これらのネイティブ符号位置のバージョンが何であっても一致します。
16041585これらは "Unicode" 範囲と呼ばれます。
16051586いずれかの端点が C<\N{...}> 形式の場合、範囲は Unicode と見なされます。
16061587もう一方の端点が移植性がない形で指定されている場合、
16071588C<S<"use re 'strict'">> の下で C<regexp> 警告が発生します:
16081589
16091590 [\N{U+00}-\x09] # Warning under re 'strict'; \x09 is non-portable
16101591 [\N{U+00}-\t] # No warning;
16111592
16121593=begin original
16131594
16141595Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ...
16151596C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a
16161597mistake so the warning is raised (under C<re 'strict'>) for it.
16171598
16181599=end original
16191600
16201601前述の両方とも文字 C<\N{U+00}> C<\N{U+01}>, ...
16211602C<\N{U+08}>, C<\N{U+09}> にマッチングしますが、
16221603C<\x09> は誤りのように見えるので、
16231604(C<re 'strict'> の下で) 警告が発生します。
16241605
16251606=begin original
16261607
16271608Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any
16281609subranges of these match what an English-only speaker would expect them
16291610to match on any platform. That is, C<[A-Z]> matches the 26 ASCII
16301611uppercase letters;
16311612C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10
16321613digits. Subranges, like C<[h-k]>, match correspondingly, in this case
16331614just the four letters C<"h">, C<"i">, C<"j">, and C<"k">. This is the
16341615natural behavior on ASCII platforms where the code points (ordinal
16351616values) for C<"h"> through C<"k"> are consecutive integers (0x68 through
163616170x6B). But special handling to achieve this may be needed on platforms
16371618with a non-ASCII native character set. For example, on EBCDIC
16381619platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is
163916200x91, and C<"k"> is 0x92. Perl specially treats C<[h-k]> to exclude the
16401621seven code points in the gap: 0x8A through 0x90. This special handling is
16411622only invoked when the range is a subrange of one of the ASCII uppercase,
16421623lowercase, and digit ranges, AND each end of the range is expressed
16431624either as a literal, like C<"A">, or as a named character (C<\N{...}>,
16441625including the C<\N{U+...> form).
16451626
16461627=end original
16471628
16481629Perl はまた、範囲 C<A-Z>、C<a-z>、C<0-9>、およびこれらの部分範囲が、
16491630英語のみの話者が一致すると予想する範囲とどのプラットフォームでも
16501631一致することを保証します。
16511632つまり、C<[A-Z]> はASCII の大文字 26 文字と一致します;
16521633C<[a-z]> は小文字 26 文字と一致します;
16531634C<[0-9]>は 10 の数字と一致します。
16541635C<[h-k]> のような部分範囲もこれに対応して一致します;
16551636この場合、4 文字 C<"h">、C<"i">、C<"j">、C<"k"> だけが一致します。
16561637これは、C<"h"> から C<"k"> までの符号位置(序数値)が連続した
16571638整数(0x68 から 0x6B)である ASCII プラットフォームでの自然な動作です。
16581639しかし、非 ASCII ネイティブ文字集合を持つプラットフォームでは、
16591640これを実現するための特別な処理が必要になるかもしれません。
16601641たとえば、EBCDIC プラットフォームでは、C<"h"> のコードポイントは
166116420x88、C<"i"> は 0x89、C<"j"> は 0x91、C<"k"> は 0x92 です。
16621643Perl は C<[h-k]> を特別に扱い、隙間にある七つの符号位置
16631644(0x8A から 0x90)を除外します。
16641645この特殊処理は、範囲が ASCII の大文字、小文字、数字の範囲の
16651646いずれかの部分範囲であり、範囲の両端が C<"A"> のようなリテラル
16661647または名前付き文字(C<\N{...}>(C<\N{U+...> 形式を含む))として表現されている
16671648場合にのみ呼び出されます。
16681649
16691650=begin original
16701651
16711652EBCDIC Examples:
16721653
16731654=end original
16741655
16751656EBCDIC の例:
16761657
16771658 [i-j] # Matches either "i" or "j"
16781659 [i-\N{LATIN SMALL LETTER J}] # Same
16791660 [i-\N{U+6A}] # Same
16801661 [\N{U+69}-\N{U+6A}] # Same
16811662 [\x{89}-\x{91}] # Matches 0x89 ("i"), 0x8A .. 0x90, 0x91 ("j")
16821663 [i-\x{91}] # Same
16831664 [\x{89}-j] # Same
16841665 [i-J] # Matches, 0x89 ("i") .. 0xC1 ("J"); special
16851666 # handling doesn't apply because range is mixed
16861667 # case
16871668
16881669=head3 Negation
16891670
16901671(否定)
16911672
16921673=begin original
16931674
16941675It is also possible to instead list the characters you do not want to
16951676match. You can do so by using a caret (C<^>) as the first character in the
16961677character class. For instance, C<[^a-z]> matches any character that is not a
16971678lowercase ASCII letter, which therefore includes more than a million
16981679Unicode code points. The class is said to be "negated" or "inverted".
16991680
17001681=end original
17011682
17021683代わりにマッチングしたくない文字の一覧を指定することも可能です。
17031684文字クラスの先頭の文字としてキャレット (C<^>) を使うことで実現します。
17041685例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします;
17051686従って 100 万種類以上の Unicode 符号位置が含まれます。
17061687このクラスは「否定」("negated") や「反転」("inverted")と呼ばれます。
17071688
17081689=begin original
17091690
17101691This syntax make the caret a special character inside a bracketed character
17111692class, but only if it is the first character of the class. So if you want
17121693the caret as one of the characters to match, either escape the caret or
17131694else don't list it first.
17141695
17151696=end original
17161697
17171698この文法はキャレットを大かっこ文字クラスの内側で特別な文字にしますが、
17181699クラスの最初の文字の場合のみです。
17191700それでマッチングしたい文字の一つでキャレットを使いたい場合、キャレットを
17201701エスケープするか、最初以外の位置に書いてください。
17211702
17221703=begin original
17231704
17241705In inverted bracketed character classes, Perl ignores the Unicode rules
17251706that normally say that named sequence, and certain characters should
17261707match a sequence of multiple characters use under caseless C</i>
17271708matching. Following those rules could lead to highly confusing
17281709situations:
17291710
17301711=end original
17311712
17321713否定大かっこ文字クラスでは、通常は大文字小文字を無視した C</i> マッチングの
17331714下では名前空間とある種の文字が複数の文字並びにマッチングするということを
17341715Perl は無視します。
17351716これらの規則に従うととても混乱する状況を引き起こすことになるからです:
17361717
17371718 "ss" =~ /^[^\xDF]+$/ui; # Matches!
17381719
17391720=begin original
17401721
17411722This should match any sequences of characters that aren't C<\xDF> nor
17421723what C<\xDF> matches under C</i>. C<"s"> isn't C<\xDF>, but Unicode
17431724says that C<"ss"> is what C<\xDF> matches under C</i>. So which one
17441725"wins"? Do you fail the match because the string has C<ss> or accept it
17451726because it has an C<s> followed by another C<s>? Perl has chosen the
17461727latter. (See note in L</Bracketed Character Classes> above.)
17471728
17481729=end original
17491730
17501731これは C</i> の下では C<\xDF> または C<\xDF> にマッチングするもの以外の
17511732任意の文字並びにマッチングするべきです。
17521733C<"s"> は C<\xDF> ではありませんが、
17531734C</i> の下では C<"ss"> は C<\xDF> がマッチングするものと Unicode は
17541735言っています。
17551736ではどちらが「勝つ」のでしょうか?
17561737文字列は C<ss> だからマッチングに失敗するのでしょうか、
17571738それともこれは C<s> の後にもう一つの C<s> があるから成功するのでしょうか?
17581739Perl は後者を選択しました。
17591740(前述の L</Bracketed Character Classes> を参照してください。)
17601741
17611742=begin original
17621743
17631744Examples:
17641745
17651746=end original
17661747
17671748例:
17681749
17691750=begin original
17701751
17711752 "e" =~ /[^aeiou]/ # No match, the 'e' is listed.
17721753 "x" =~ /[^aeiou]/ # Match, as 'x' isn't a lowercase vowel.
17731754 "^" =~ /[^^]/ # No match, matches anything that isn't a caret.
17741755 "^" =~ /[x^]/ # Match, caret is not special here.
17751756
17761757=end original
17771758
17781759 "e" =~ /[^aeiou]/ # マッチングしない; 'e' がある。
17791760 "x" =~ /[^aeiou]/ # マッチング; 'x' は小文字の母音ではない。
17801761 "^" =~ /[^^]/ # マッチングしない; キャレット以外全てにマッチング。
17811762 "^" =~ /[x^]/ # マッチング; キャレットはここでは特別ではない。
17821763
17831764=head3 Backslash Sequences
17841765
17851766(逆スラッシュシーケンス)
17861767
17871768=begin original
17881769
17891770You can put any backslash sequence character class (with the exception of
17901771C<\N> and C<\R>) inside a bracketed character class, and it will act just
17911772as if you had put all characters matched by the backslash sequence inside the
17921773character class. For instance, C<[a-f\d]> matches any decimal digit, or any
17931774of the lowercase letters between 'a' and 'f' inclusive.
17941775
17951776=end original
17961777
17971778大かっこ文字クラスの中に(C<\N> と C<\R> を例外として)逆スラッシュシーケンス
17981779文字クラスを置くことができ、逆スラッシュシーケンスにマッチングする全ての
17991780文字を文字クラスの中に置いたかのように動作します。
18001781例えば、C<[a-f\d]> は任意の 10 進数字、あるいは 'a' から 'f' までの小文字に
18011782マッチングします。
18021783
18031784=begin original
18041785
18051786C<\N> within a bracketed character class must be of the forms C<\N{I<name>}>
18061787or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines,
18071788for the same reason that a dot C<.> inside a bracketed character class loses
18081789its special meaning: it matches nearly anything, which generally isn't what you
18091790want to happen.
18101791
18111792=end original
18121793
18131794大かっこ文字クラスの中のドット C<.> が特別な意味を持たないのと同じ理由で、
18141795大かっこ文字クラスの中の C<\N> は C<\N{I<name>}> または
18151796C<\N{U+I<hex char>}> の形式で、かつ非改行マッチング形式でない形でなければ
18161797なりません: これはほとんど何でもマッチングするので、一般的には起こって
18171798欲しいことではありません。
18181799
18191800=begin original
18201801
18211802Examples:
18221803
18231804=end original
18241805
18251806例:
18261807
18271808=begin original
18281809
18291810 /[\p{Thai}\d]/ # Matches a character that is either a Thai
18301811 # character, or a digit.
18311812 /[^\p{Arabic}()]/ # Matches a character that is neither an Arabic
18321813 # character, nor a parenthesis.
18331814
18341815=end original
18351816
18361817 /[\p{Thai}\d]/ # タイ文字または数字の文字に
18371818 # マッチングする。
18381819 /[^\p{Arabic}()]/ # アラビア文字でもかっこでもない文字に
18391820 # マッチングする。
18401821
18411822=begin original
18421823
18431824Backslash sequence character classes cannot form one of the endpoints
18441825of a range. Thus, you can't say:
18451826
18461827=end original
18471828
18481829逆スラッシュシーケンス文字クラスは範囲の端点の一つにはできません。
18491830従って、以下のようにはできません:
18501831
18511832 /[\p{Thai}-\d]/ # Wrong!
18521833
18531834=head3 POSIX Character Classes
18541835X<character class> X<\p> X<\p{}>
18551836X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph>
18561837X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit>
18571838
18581839(POSIX 文字クラス)
18591840
18601841=begin original
18611842
18621843POSIX character classes have the form C<[:class:]>, where I<class> is the
18631844name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear
18641845I<inside> bracketed character classes, and are a convenient and descriptive
18651846way of listing a group of characters.
18661847
18671848=end original
18681849
18691850POSIX 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は
18701851デリミタです。
18711852POSIX 文字クラスは大かっこ文字クラスの I<内側> にのみ現れ、文字のグループを
18721853一覧するのに便利で記述的な方法です。
18731854
18741855=begin original
18751856
18761857Be careful about the syntax,
18771858
18781859=end original
18791860
18801861文法について注意してください、
18811862
18821863 # Correct:
18831864 $string =~ /[[:alpha:]]/
18841865
18851866 # Incorrect (will warn):
18861867 $string =~ /[:alpha:]/
18871868
18881869=begin original
18891870
18901871The latter pattern would be a character class consisting of a colon,
18911872and the letters C<a>, C<l>, C<p> and C<h>.
18921873POSIX character classes can be part of a larger bracketed character class.
18931874For example,
18941875
18951876=end original
18961877
18971878後者のパターンは、コロンおよび C<a>, C<l>, C<p>, C<h> の文字からなる
18981879文字クラスです。
18991880これら文字クラスはより大きな大かっこ文字クラスの一部にできます。
19001881例えば、
19011882
19021883 [01[:alpha:]%]
19031884
19041885=begin original
19051886
19061887is valid and matches '0', '1', any alphabetic character, and the percent sign.
19071888
19081889=end original
19091890
19101891これは妥当で、'0'、'1'、任意の英字、パーセントマークにマッチングします。
19111892
19121893=begin original
19131894
19141895Perl recognizes the following POSIX character classes:
19151896
19161897=end original
19171898
19181899Perl は以下の POSIX 文字クラスを認識します:
19191900
19201901=begin original
19211902
1922 alpha Any alphabetical character (e.g., [A-Za-z]).
1903 alpha Any alphabetical character ("[A-Za-z]").
1923 alnum Any alphanumeric character (e.g., [A-Za-z0-9]).
1904 alnum Any alphanumeric character ("[A-Za-z0-9]").
19241905 ascii Any character in the ASCII character set.
19251906 blank A GNU extension, equal to a space or a horizontal tab ("\t").
19261907 cntrl Any control character. See Note [2] below.
1927 digit Any decimal digit (e.g., [0-9]), equivalent to "\d".
1908 digit Any decimal digit ("[0-9]"), equivalent to "\d".
19281909 graph Any printable character, excluding a space. See Note [3] below.
1929 lower Any lowercase character (e.g., [a-z]).
1910 lower Any lowercase character ("[a-z]").
19301911 print Any printable character, including a space. See Note [4] below.
19311912 punct Any graphical character excluding "word" characters. Note [5].
19321913 space Any whitespace character. "\s" including the vertical tab
19331914 ("\cK").
1934 upper Any uppercase character (e.g., [A-Z]).
1915 upper Any uppercase character ("[A-Z]").
1935 word A Perl extension (e.g., [A-Za-z0-9_]), equivalent to "\w".
1916 word A Perl extension ("[A-Za-z0-9_]"), equivalent to "\w".
1936 xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]). Note [7].
1917 xdigit Any hexadecimal digit ("[0-9a-fA-F]").
19371918
19381919=end original
19391920
1940 alpha 任意の英字 (例: [A-Za-z])。
1921 alpha 任意の英字 ("[A-Za-z]")。
1941 alnum 任意の英数字。(例: [A-Za-z0-9])
1922 alnum 任意の英数字。("[A-Za-z0-9]")
19421923 ascii 任意の ASCII 文字集合の文字。
1943 blank GNU 拡張; スペースまたは水平タブ (\t) と同じ。
1924 blank GNU 拡張; スペースまたは水平タブ ("\t") と同じ。
19441925 cntrl 任意の制御文字。後述の [2] 参照。
1945 digit 任意の 10 進数字 (例: [0-9]); "\d" と等価。
1926 digit 任意の 10 進数字 ("[0-9]"); "\d" と等価。
19461927 graph 任意の表示文字; スペースを除く。後述の [3] 参照。
1947 lower 任意の小文字 (例: [a-z])。
1928 lower 任意の小文字 ("[a-z]")。
19481929 print 任意の表示文字; スペースを含む。後述の [4] 参照。
19491930 punct 任意の「単語」文字を除く表示文字。[5] 参照。
19501931 space 任意の空白文字。水平タブ ("\cK") を含む "\s"。
1951 upper 任意の大文字 (例: [A-Z])。
1932 upper 任意の大文字 ("[A-Z]")。
1952 word Perl 拡張 (例: [A-Za-z0-9_]); "\w" と等価。
1933 word Perl 拡張 ("[A-Za-z0-9_]"); "\w" と等価。
1953 xdigit 任意の 16 進文字 (例: [0-9a-fA-F])。[7] 参照
1934 xdigit 任意の 16 進文字 ("[0-9a-fA-F]")。
19541935
19551936=begin original
19561937
19571938Like the L<Unicode properties|/Unicode Properties>, most of the POSIX
19581939properties match the same regardless of whether case-insensitive (C</i>)
19591940matching is in effect or not. The two exceptions are C<[:upper:]> and
19601941C<[:lower:]>. Under C</i>, they each match the union of C<[:upper:]> and
19611942C<[:lower:]>.
19621943
19631944=end original
19641945
19651946L<Unicode properties|/Unicode Properties> と同様、
19661947ほとんどの POSIX 特性は、大文字小文字無視 (C</i>) が有効かどうかに関わらず
19671948同じものにマッチングします。
19681949二つの例外は C<[:upper:]> と C<[:lower:]> です。
19691950C</i> の下では、これらそれぞれ C<[:upper:]> と C<[:lower:]> の和集合に
19701951マッチングします。
19711952
19721953=begin original
19731954
19741955Most POSIX character classes have two Unicode-style C<\p> property
19751956counterparts. (They are not official Unicode properties, but Perl extensions
19761957derived from official Unicode properties.) The table below shows the relation
19771958between POSIX character classes and these counterparts.
19781959
19791960=end original
19801961
19811962ほとんどの POSIX 文字クラスには、対応する二つの Unicode 式の C<\p> 特性が
19821963あります。
19831964(これは公式 Unicode 特性ではなく、公式 Unicode 特性から派生した Perl
19841965エクステンションです。)
19851966以下の表は POSIX 文字クラスと対応するものとの関連を示します。
19861967
19871968=begin original
19881969
19891970One counterpart, in the column labelled "ASCII-range Unicode" in
19901971the table, matches only characters in the ASCII character set.
19911972
19921973=end original
19931974
19941975対応物の一つである、表で "ASCII-range Unicode" と書かれた列のものは、
19951976ASCII 文字集合の文字にのみマッチングします。
19961977
19971978=begin original
19981979
19991980The other counterpart, in the column labelled "Full-range Unicode", matches any
20001981appropriate characters in the full Unicode character set. For example,
20011982C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any
20021983character in the entire Unicode character set considered alphabetic.
20031984An entry in the column labelled "backslash sequence" is a (short)
20041985equivalent.
20051986
20061987=end original
20071988
20081989もう一つの対応物である、"Full-range Unicode" と書かれた列のものは、
20091990Unicode 文字集合全体の中の適切な任意の文字にマッチングします。
20101991例えば、C<\p{Alpha}> は単に ASCII アルファベット文字だけでなく、
20111992Unicode 文字集合全体の中からアルファベットと考えられる任意の文字に
20121993マッチングします。
20131994"backslash sequence" の列は (短い) 同義語です。
20141995
20151996 [[:...:]] ASCII-range Full-range backslash Note
20161997 Unicode Unicode sequence
20171998 -----------------------------------------------------
20181999 alpha \p{PosixAlpha} \p{XPosixAlpha}
20192000 alnum \p{PosixAlnum} \p{XPosixAlnum}
20202001 ascii \p{ASCII}
20212002 blank \p{PosixBlank} \p{XPosixBlank} \h [1]
20222003 or \p{HorizSpace} [1]
20232004 cntrl \p{PosixCntrl} \p{XPosixCntrl} [2]
20242005 digit \p{PosixDigit} \p{XPosixDigit} \d
20252006 graph \p{PosixGraph} \p{XPosixGraph} [3]
20262007 lower \p{PosixLower} \p{XPosixLower}
20272008 print \p{PosixPrint} \p{XPosixPrint} [4]
20282009 punct \p{PosixPunct} \p{XPosixPunct} [5]
20292010 \p{PerlSpace} \p{XPerlSpace} \s [6]
20302011 space \p{PosixSpace} \p{XPosixSpace} [6]
20312012 upper \p{PosixUpper} \p{XPosixUpper}
20322013 word \p{PosixWord} \p{XPosixWord} \w
2033 xdigit \p{PosixXDigit} \p{XPosixXDigit} [7]
2014 xdigit \p{PosixXDigit} \p{XPosixXDigit}
20342015
20352016=over 4
20362017
20372018=item [1]
20382019
20392020=begin original
20402021
20412022C<\p{Blank}> and C<\p{HorizSpace}> are synonyms.
20422023
20432024=end original
20442025
20452026C<\p{Blank}> と C<\p{HorizSpace}> は同義語です。
20462027
20472028=item [2]
20482029
20492030=begin original
20502031
20512032Control characters don't produce output as such, but instead usually control
20522033the terminal somehow: for example, newline and backspace are control characters.
20532034On ASCII platforms, in the ASCII range, characters whose code points are
20542035between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on
20552036EBCDIC platforms, their counterparts are control characters.
20562037
20572038=end original
20582039
20592040制御文字はそれ自体は出力されず、普通は何か端末を制御します: 例えば
20602041改行と後退は制御文字です。
20612042ASCII プラットフォームで、ASCII の範囲では、符号位置が 0 から 31 までの
20622043範囲の文字および 127 (C<DEL>) が制御文字です;
20632044EBCDIC プラットフォームでは、対応するものは制御文字です。
20642045
20652046=item [3]
20662047
20672048=begin original
20682049
20692050Any character that is I<graphical>, that is, visible. This class consists
20702051of all alphanumeric characters and all punctuation characters.
20712052
20722053=end original
20732054
20742055I<graphical>、つまり見える文字。
20752056このクラスは全ての英数字と全ての句読点文字。
20762057
20772058=item [4]
20782059
20792060=begin original
20802061
20812062All printable characters, which is the set of all graphical characters
20822063plus those whitespace characters which are not also controls.
20832064
20842065=end original
20852066
20862067全ての表示可能な文字; 全ての graphical 文字に加えて制御文字でない空白文字。
20872068
20882069=item [5]
20892070
20902071=begin original
20912072
20922073C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all
20932074non-controls, non-alphanumeric, non-space characters:
20942075C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect,
20952076it could alter the behavior of C<[[:punct:]]>).
20962077
20972078=end original
20982079
20992080ASCII の範囲の C<\p{PosixPunct}> と C<[[:punct:]]> は全ての非制御、非英数字、
21002081非空白文字にマッチングします:
21012082C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (しかしロケールが有効なら、
21022083C<[[:punct:]]> の振る舞いが変わります)。
21032084
21042085=begin original
21052086
21062087The similarly named property, C<\p{Punct}>, matches a somewhat different
21072088set in the ASCII range, namely
21082089C<[-!"#%&'()*,./:;?@[\\\]_{}]>. That is, it is missing the nine
21092090characters C<[$+E<lt>=E<gt>^`|~]>.
21102091This is because Unicode splits what POSIX considers to be punctuation into two
21112092categories, Punctuation and Symbols.
21122093
21132094=end original
21142095
21152096似たような名前の特性 C<\p{Punct}> は、ASCII 範囲の異なる集合である
21162097C<[-!"#%&'()*,./:;?@[\\\]_{}]> にマッチングします。
21172098つまり、C<[$+E<lt>=E<gt>^`|~]> の 9 文字はありません。
21182099これは、Unicode は POSIX が句読点と考えるものを二つのカテゴリ
21192100Punctuation と Symbols に分けているからです。
21202101
21212102=begin original
21222103
21232104C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what
21242105C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}>
21252106matches. This is different than strictly matching according to
21262107C<\p{Punct}>. Another way to say it is that
21272108if Unicode rules are in effect, C<[[:punct:]]> matches all characters
21282109that Unicode considers punctuation, plus all ASCII-range characters that
21292110Unicode considers symbols.
21302111
21312112=end original
21322113
21332114C<\p{XPosixPunct}> と (Unicode の規則の下での) C<[[:punct:]]> は、
21342115ASCII の範囲で C<\p{PosixPunct}> がマッチングする物に加えて、
21352116C<\p{Punct}> がマッチングする物にマッチングします。
21362117これは C<\p{Punct}> に従って正確にマッチングする物と異なります。
21372118Unicode 規則が有効な場合のもう一つの言い方は、C<[[:punct:]]> は Unicode が
21382119句読点として扱うものに加えて、Unicode が "symbols" として扱う ASCII 範囲の
21392120全ての文字にマッチングします。
21402121
21412122=item [6]
21422123
21432124=begin original
21442125
21452126C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl
21462127v5.18. In earlier versions, these differ only in that in non-locale
21472128matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>.
21482129Same for the two ASCII-only range forms.
21492130
21502131=end original
21512132
21522133C<\p{XPerlSpace}> と C<\p{Space}> は、Perl v5.18 からは同じように
21532134マッチングします。
21542135以前のバージョンでは、これらの違いは、非ロケールマッチングでは
21552136C<\p{XPerlSpace}> は垂直タブ C<\cK> にもマッチングしないということだけです。
21562137二つの ASCII のみの範囲の形式では同じです。
21572138
2158=item [7]
2159
2160=begin original
2161
2162Unlike C<[[:digit:]]> which matches digits in many writing systems, such
2163as Thai and Devanagari, there are currently only two sets of hexadecimal
2164digits, and it is unlikely that more will be added. This is because you
2165not only need the ten digits, but also the six C<[A-F]> (and C<[a-f]>)
2166to correspond. That means only the Latin script is suitable for these,
2167and Unicode has only two sets of these, the familiar ASCII set, and the
2168fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO).
2169
2170=end original
2171
2172タイ文字やデバナーガリ文字のように多くの書記体系の数字にマッチングする
2173C<[[:digit:]]> と異なり、16 進数の二つの集合だけで、これ以上追加されることは
2174おそらくありません。
2175これは、対応するのに 10 の数字だけでなく、6 個の C<[A-F]> (および C<[a-f]>) も
2176必要だからです。
2177これは、Latin 用字のみがこれらに適合していて、
2178Unicode はこれらの二つの集合、つまり慣れ親しんだ
2179ASCII 集合と、U+FF10 (FULLWIDTH DIGIT ZERO) から始まる全角形式のみを
2180持つということです。
2181
21822139=back
21832140
21842141=begin original
21852142
21862143There are various other synonyms that can be used besides the names
21872144listed in the table. For example, C<\p{XPosixAlpha}> can be written as
21882145C<\p{Alpha}>. All are listed in
21892146L<perluniprops/Properties accessible through \p{} and \P{}>.
21902147
21912148=end original
21922149
21932150表に挙げられている名前以外にも様々なその他の同義語が使えます。
21942151例えば、C<\p{XPosixAlpha}> は C<\p{Alpha}> と書けます。
21952152全ての一覧は
21962153L<perluniprops/Properties accessible through \p{} and \P{}> に
21972154あります。
21982155
21992156=begin original
22002157
22012158Both the C<\p> counterparts always assume Unicode rules are in effect.
22022159On ASCII platforms, this means they assume that the code points from 128
22032160to 255 are Latin-1, and that means that using them under locale rules is
22042161unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the
22052162POSIX character classes are useful under locale rules. They are
22062163affected by the actual rules in effect, as follows:
22072164
22082165=end original
22092166
22102167C<\p> に対応するものの両方は常に Unicode の規則が有効であることを仮定します。
22112168これは、ASCII プラットフォームでは、128 から 255 の符号位置は
22122169Latin-1 であることを仮定するということで、ロケールの規則の下で
22132170これらを使うということは、ロケールが Latin-1 か UTF-8 であることが
22142171補償されていない限り賢明ではないということです。
22152172一方、POSIX 文字クラスはロケールの規則の下で有用です。
22162173これらは次のように、実際に有効な規則に影響を受けます:
22172174
22182175=over
22192176
22202177=item If the C</a> modifier, is in effect ...
22212178
22222179(C</a> が有効なら...)
22232180
22242181=begin original
22252182
22262183Each of the POSIX classes matches exactly the same as their ASCII-range
22272184counterparts.
22282185
22292186=end original
22302187
22312188それぞれの POSIX クラスは ASCII の範囲で対応する正確に同じものに
22322189マッチングします。
22332190
22342191=item otherwise ...
22352192
22362193(さもなければ ...)
22372194
22382195=over
22392196
22402197=item For code points above 255 ...
22412198
22422199(256 以上の符号位置では ...)
22432200
22442201=begin original
22452202
22462203The POSIX class matches the same as its Full-range counterpart.
22472204
22482205=end original
22492206
22502207POSIX クラスはその Full の範囲で対応する同じものにマッチングします。
22512208
22522209=item For code points below 256 ...
22532210
22542211(255 以下の符号位置では ...)
22552212
22562213=over
22572214
22582215=item if locale rules are in effect ...
22592216
22602217(ロケール規則が有効なら ...)
22612218
22622219=begin original
22632220
22642221The POSIX class matches according to the locale, except:
22652222
22662223=end original
22672224
22682225POSIX クラスはロケールに従ってマッチングします; 例外は:
22692226
22702227=over
22712228
22722229=item C<word>
22732230
22742231=begin original
22752232
22762233also includes the platform's native underscore character, no matter what
22772234the locale is.
22782235
22792236=end original
22802237
22812238それに加えて、ロケールが何かに関わらず、プラットフォームのネイティブな
22822239下線文字を使います。
22832240
22842241=item C<ascii>
22852242
22862243=begin original
22872244
22882245on platforms that don't have the POSIX C<ascii> extension, this matches
22892246just the platform's native ASCII-range characters.
22902247
22912248=end original
22922249
22932250POSIX C<ascii> 拡張を持たないプラットフォームでは、
22942251これは単にプラットフォームのネイティブな ASCII の範囲の文字に
22952252マッチングします。
22962253
22972254=item C<blank>
22982255
22992256=begin original
23002257
23012258on platforms that don't have the POSIX C<blank> extension, this matches
23022259just the platform's native tab and space characters.
23032260
23042261=end original
23052262
23062263on platforms that don't have the
23072264POSIX C<blank> 格調を持たないプラットフォームでは、
23082265これは単にプラットフォームのネイティブなタブとすぺーす文字に
23092266マッチングします。
23102267
23112268=back
23122269
23132270=item if, instead, Unicode rules are in effect ...
23142271
23152272(そうではなく、Unicode 規則が有効なら ...)
23162273
23172274=begin original
23182275
23192276The POSIX class matches the same as the Full-range counterpart.
23202277
23212278=end original
23222279
23232280POSIX クラスは Full の範囲の対応する同じものにマッチングします。
23242281
23252282=item otherwise ...
23262283
23272284(さもなければ ...)
23282285
23292286=begin original
23302287
23312288The POSIX class matches the same as the ASCII range counterpart.
23322289
23332290=end original
23342291
23352292POSIX クラスは ASCII の範囲の同じものにマッチングします。
23362293
23372294=back
23382295
23392296=back
23402297
23412298=back
23422299
23432300=begin original
23442301
23452302Which rules apply are determined as described in
23462303L<perlre/Which character set modifier is in effect?>.
23472304
23482305=end original
23492306
23502307どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
23512308記述されている方法で決定されます。
23522309
2310=begin original
2311
2312It is proposed to change this behavior in a future release of Perl so that
2313whether or not Unicode rules are in effect would not change the
2314behavior: Outside of locale, the POSIX classes
2315would behave like their ASCII-range counterparts. If you wish to
2316comment on this proposal, send email to C<perl5-porters@perl.org>.
2317
2318=end original
2319
2320Perl の将来のバージョンではこの振る舞いを変えることが提案されています;
2321Unicode の規則が有効かどうかは振る舞いを変えません:
2322ロケールの外側では、
2323POSIX クラスはその ASCII の範囲の対応するものと同様に振る舞います。
2324この提案にコメントしたいなら、C<perl5-porters@perl.org> にメールを
2325送ってください。
2326
23532327=head4 Negation of POSIX character classes
23542328X<character class, negation>
23552329
23562330(POSIX 文字クラスの否定)
23572331
23582332=begin original
23592333
23602334A Perl extension to the POSIX character class is the ability to
23612335negate it. This is done by prefixing the class name with a caret (C<^>).
23622336Some examples:
23632337
23642338=end original
23652339
23662340POSIX 文字クラスに対する Perl の拡張は否定の機能です。
23672341これはクラス名の前にキャレット (C<^>) を置くことで実現します。
23682342いくつかの例です:
23692343
23702344 POSIX ASCII-range Full-range backslash
23712345 Unicode Unicode sequence
23722346 -----------------------------------------------------
23732347 [[:^digit:]] \P{PosixDigit} \P{XPosixDigit} \D
23742348 [[:^space:]] \P{PosixSpace} \P{XPosixSpace}
23752349 \P{PerlSpace} \P{XPerlSpace} \S
23762350 [[:^word:]] \P{PerlWord} \P{XPosixWord} \W
23772351
23782352=begin original
23792353
23802354The backslash sequence can mean either ASCII- or Full-range Unicode,
23812355depending on various factors as described in L<perlre/Which character set modifier is in effect?>.
23822356
23832357=end original
23842358
23852359逆スラッシュシーケンスは ASCII- か Full-range Unicode のどちらかを意味します;
23862360どちらが使われるかは L<perlre/Which character set modifier is in effect?> で
23872361記述されている様々な要素に依存します。
23882362
23892363=head4 [= =] and [. .]
23902364
23912365([= =] と [. .])
23922366
23932367=begin original
23942368
23952369Perl recognizes the POSIX character classes C<[=class=]> and
23962370C<[.class.]>, but does not (yet?) support them. Any attempt to use
23972371either construct raises an exception.
23982372
23992373=end original
24002374
24012375Perl は POSIX 文字クラス C<[=class=]> と C<[.class.]> を認識しますが、
24022376これらには(まだ?)対応していません。
24032377このような構文を使おうとすると例外が発生します。
24042378
24052379=head4 Examples
24062380
24072381(例)
24082382
24092383=begin original
24102384
24112385 /[[:digit:]]/ # Matches a character that is a digit.
24122386 /[01[:lower:]]/ # Matches a character that is either a
24132387 # lowercase letter, or '0' or '1'.
24142388 /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
24152389 # except the letters 'a' to 'f' and 'A' to
24162390 # 'F'. This is because the main character
24172391 # class is composed of two POSIX character
24182392 # classes that are ORed together, one that
24192393 # matches any digit, and the other that
24202394 # matches anything that isn't a hex digit.
24212395 # The OR adds the digits, leaving only the
24222396 # letters 'a' to 'f' and 'A' to 'F' excluded.
24232397
24242398=end original
24252399
24262400 /[[:digit:]]/ # 数字の文字にマッチングする。
24272401 /[01[:lower:]]/ # 小文字、'0'、'1' のいずれかの文字に
24282402 # マッチングする。
24292403 /[[:digit:][:^xdigit:]]/ # 'a' から 'f' と 'A' から 'F' 以外の任意の文字に
24302404 # マッチング。これはメインの文字クラスでは二つの
24312405 # POSIX 文字クラスが OR され、一つは任意の数字に
24322406 # マッチングし、もう一つは 16 進文字でない全ての
24332407 # 文字にマッチングします。OR は数字を加え、
24342408 # 'a' から 'f' および 'A' から 'F' のみが
24352409 # 除外されて残ります。
24362410 #
24372411
24382412=head3 Extended Bracketed Character Classes
24392413X<character class>
24402414X<set operations>
24412415
24422416(拡張大かっこ文字クラス)
24432417
24442418=begin original
24452419
24462420This is a fancy bracketed character class that can be used for more
24472421readable and less error-prone classes, and to perform set operations,
24482422such as intersection. An example is
24492423
24502424=end original
24512425
24522426これはしゃれた大かっこ文字クラスで、より読みやすく、エラーが発生しにくい
24532427クラスや、交差などの集合演算を実行するために使用できます。
24542428
24552429 /(?[ \p{Thai} & \p{Digit} ])/
24562430
24572431=begin original
24582432
24592433This will match all the digit characters that are in the Thai script.
24602434
24612435=end original
24622436
24632437これは、タイ語スクリプト内のすべての数字と一致します。
24642438
24652439=begin original
24662440
24672441This is an experimental feature available starting in 5.18, and is
24682442subject to change as we gain field experience with it. Any attempt to
24692443use it will raise a warning, unless disabled via
24702444
24712445=end original
24722446
24732447これは 5.18 から利用できる実験的な機能で、現場での経験を積むにつれて
24742448変更される可能性があります。
24752449これを使用しようとすると、次のようにして無効にしない限り、警告が表示されます:
24762450
24772451 no warnings "experimental::regex_sets";
24782452
24792453=begin original
24802454
24812455Comments on this feature are welcome; send email to
24822456C<perl5-porters@perl.org>.
24832457
24842458=end original
24852459
24862460この機能に関するコメントを歓迎します。
24872461C<perl5-porters@perl.org> に電子メールを送ってください。
24882462
24892463=begin original
24902464
24912465The rules used by L<C<use re 'strict>|re/'strict' mode> apply to this
24922466construct.
24932467
24942468=end original
24952469
24962470L<C<use re 'strict>|re/'strict' mode> で使われる規則はこの構文に
24972471適用されます。
24982472
24992473=begin original
25002474
25012475We can extend the example above:
25022476
25032477=end original
25042478
25052479上記の例を拡張できます:
25062480
25072481 /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/
25082482
25092483=begin original
25102484
25112485This matches digits that are in either the Thai or Laotian scripts.
25122486
25132487=end original
25142488
25152489これはタイ語またはラオス語のいずれかの数字と一致します。
25162490
25172491=begin original
25182492
25192493Notice the white space in these examples. This construct always has
25202494the C<E<sol>xx> modifier turned on within it.
25212495
25222496=end original
25232497
25242498これらの例の中の空白に注意してください。
25252499この構文では、その中では常に C<E<sol>xx> 修飾子がオンになっています。
25262500
25272501=begin original
25282502
25292503The available binary operators are:
25302504
25312505=end original
25322506
25332507使用可能な 2 項演算子は次のとおりです:
25342508
25352509 & intersection
25362510 + union
25372511 | another name for '+', hence means union
25382512 - subtraction (the result matches the set consisting of those
25392513 code points matched by the first operand, excluding any that
25402514 are also matched by the second operand)
25412515 ^ symmetric difference (the union minus the intersection). This
25422516 is like an exclusive or, in that the result is the set of code
25432517 points that are matched by either, but not both, of the
25442518 operands.
25452519
25462520=begin original
25472521
25482522There is one unary operator:
25492523
25502524=end original
25512525
25522526単項演算子が一つあります。
25532527
25542528 ! complement
25552529
25562530=begin original
25572531
25582532All the binary operators left associate; C<"&"> is higher precedence
25592533than the others, which all have equal precedence. The unary operator
25602534right associates, and has highest precedence. Thus this follows the
25612535normal Perl precedence rules for logical operators. Use parentheses to
25622536override the default precedence and associativity.
25632537
25642538=end original
25652539
25662540すべての二項演算子は左結合です; C<"&"> はその他よりも高い優先順位を持ち、
25672541それ以外は同等の優先順位を持ちます。
25682542単項演算子は右結合で、最も高い優先順位を持ちます。
25692543従って、これは通常の Perl の論理演算子に関する優先順位規則に従います。
25702544デフォルトの優先順位と結合を上書きするにはかっこを使います。
25712545
25722546=begin original
25732547
25742548The main restriction is that everything is a metacharacter. Thus,
25752549you cannot refer to single characters by doing something like this:
25762550
25772551=end original
25782552
25792553主な制限は、すべてがメタ文字であるということです。
25802554したがって、以下のようにして単一文字を参照することはできません:
25812555
25822556 /(?[ a + b ])/ # Syntax error!
25832557
25842558=begin original
25852559
25862560The easiest way to specify an individual typable character is to enclose
25872561it in brackets:
25882562
25892563=end original
25902564
25912565タイプ可能な個々の文字を指定する最も簡単な方法は、次のように
25922566かっこで囲むことです:
25932567
25942568 /(?[ [a] + [b] ])/
25952569
25962570=begin original
25972571
25982572(This is the same thing as C<[ab]>.) You could also have said the
25992573equivalent:
26002574
26012575=end original
26022576
26032577(これはC<[ab]>と同じことです)。
26042578同じことを言うこともできます:
26052579
26062580 /(?[[ a b ]])/
26072581
26082582=begin original
26092583
26102584(You can, of course, specify single characters by using, C<\x{...}>,
26112585C<\N{...}>, etc.)
26122586
26132587=end original
26142588
26152589(もちろん、C<\x{...}> や C<\N{...}> などを使用して 1 文字を
26162590指定することもできます。)
26172591
26182592=begin original
26192593
26202594This last example shows the use of this construct to specify an ordinary
26212595bracketed character class without additional set operations. Note the
26222596white space within it. This is allowed because C<E<sol>xx> is
26232597automatically turned on within this construct.
26242598
26252599=end original
26262600
26272601この最後の例では、この構文を使用して、追加の集合操作なしで
26282602通常の大かっこ文字クラスを指定する方法を示しています。
26292603この中に空白があることに注意してください。
26302604C<E<sol>xx> は、この構文の内側で自動的に有効になるのでこれが許されます。
26312605
26322606=begin original
26332607
26342608All the other escapes accepted by normal bracketed character classes are
26352609accepted here as well.
26362610
26372611=end original
26382612
26392613通常の大かっこ文字クラスで受け入れられる他のエスケープは
26402614すべてここでも受け入れられます。
26412615
26422616=begin original
26432617
26442618Because this construct compiles under
26452619L<C<use re 'strict>|re/'strict' mode>, unrecognized escapes that
26462620generate warnings in normal classes are fatal errors here, as well as
26472621all other warnings from these class elements, as well as some
26482622practices that don't currently warn outside C<re 'strict'>. For example
26492623you cannot say
26502624
26512625=end original
26522626
26532627この構文は L<C<use re 'strict>|re/'strict' mode> の下でコンパイルされるので、
26542628通常のクラスで警告を生成する
26552629認識されないエスケープはここでは致命的なエラーです;
26562630これらのクラス要素からのその他すべての警告も同様で、
26572631C<re 'strict'> の外側では、現在警告していないいくつかのプラクティスも
26582632同様です。
26592633例えば次のようにはできません:
26602634
26612635 /(?[ [ \xF ] ])/ # Syntax error!
26622636
26632637=begin original
26642638
26652639You have to have two hex digits after a braceless C<\x> (use a leading
26662640zero to make two). These restrictions are to lower the incidence of
26672641typos causing the class to not match what you thought it would.
26682642
26692643=end original
26702644
26712645中かっこのない C<\x> の後には 2 桁の 16 進数が必要です(2 桁にするには
26722646先頭の 0 を使用します)。
26732647これらの制限は、クラスが想定したものと一致しない原因となる
26742648タイプミスの発生を減らすためです。
26752649
26762650=begin original
26772651
26782652If a regular bracketed character class contains a C<\p{}> or C<\P{}> and
26792653is matched against a non-Unicode code point, a warning may be
26802654raised, as the result is not Unicode-defined. No such warning will come
26812655when using this extended form.
26822656
26832657=end original
26842658
26852659通常の大かっこ文字クラスに C<\p{}> や C<\P{}> が含まれていて、
26862660非 Unicode 符号位置に対してマッチングした場合、
26872661結果は Unicode で定義されていないので、警告が発生します。
26882662このような警告は、拡張形式を使った場合は発生しません。
26892663
26902664=begin original
26912665
26922666The final difference between regular bracketed character classes and
26932667these, is that it is not possible to get these to match a
26942668multi-character fold. Thus,
26952669
26962670=end original
26972671
26982672通常の大かっこ文字クラスとこれらのクラスの最後の違いは、
26992673これらを複数文字畳み込みにマッチングさせることができないということです。
27002674従って:
27012675
27022676 /(?[ [\xDF] ])/iu
27032677
27042678=begin original
27052679
27062680does not match the string C<ss>.
27072681
27082682=end original
27092683
27102684は文字列 C<ss> と一致しません。
27112685
27122686=begin original
27132687
27142688You don't have to enclose POSIX class names inside double brackets,
27152689hence both of the following work:
27162690
27172691=end original
27182692
27192693POSIX クラス名を二重かっこで囲む必要はありません;
27202694そのため、以下の両方とも動作します:
27212695
27222696 /(?[ [:word:] - [:lower:] ])/
27232697 /(?[ [[:word:]] - [[:lower:]] ])/
27242698
27252699=begin original
27262700
27272701Any contained POSIX character classes, including things like C<\w> and C<\D>
27282702respect the C<E<sol>a> (and C<E<sol>aa>) modifiers.
27292703
27302704=end original
27312705
27322706C<\w> や C<\D> などの POSIX 文字クラスは、C<E<sol>a>
27332707(および C<E<sol>aa> )修飾子を尊重します。
27342708
27352709=begin original
27362710
2737Note that C<< (?[ ]) >> is a regex-compile-time construct. Any attempt
2711C<< (?[ ]) >> is a regex-compile-time construct. Any attempt to use
2738to use something which isn't knowable at the time the containing regular
2712something which isn't knowable at the time the containing regular
27392713expression is compiled is a fatal error. In practice, this means
27402714just three limitations:
27412715
27422716=end original
27432717
2744C<< (?[ ]) >> は コンパイル時正規表現構文であることに注意してください
2718C<< (?[ ]) >> は コンパイル時正規表現構文で
27452719正規表現を含むコンパイル時に未知のものを使用しようとすると、
27462720致命的なエラーになります。
27472721実際には、これは三つの制限を意味します:
27482722
27492723=over 4
27502724
27512725=item 1
27522726
27532727=begin original
27542728
27552729When compiled within the scope of C<use locale> (or the C<E<sol>l> regex
27562730modifier), this construct assumes that the execution-time locale will be
27572731a UTF-8 one, and the generated pattern always uses Unicode rules. What
27582732gets matched or not thus isn't dependent on the actual runtime locale, so
27592733tainting is not enabled. But a C<locale> category warning is raised
27602734if the runtime locale turns out to not be UTF-8.
27612735
27622736=end original
27632737
27642738C<use locale> (または C<E<sol>l> 正規表現修飾子)の
27652739スコープ内でコンパイルされると、この構文は実行時ロケールが
27662740UTF-8 のものであることを仮定し、
27672741生成されたパターンは常に Unicode の規則を使います。
27682742従ってマッチングするかどうかは実際の実行時ロケールには関係なく、
27692743汚染チェックモードは有効になりません。
27702744しかし、実行時ロケールが UTF-8 以外になると、
27712745C<locale> カテゴリの警告が発生します。
27722746
27732747=item 2
27742748
27752749=begin original
27762750
27772751Any
27782752L<user-defined property|perlunicode/"User-Defined Character Properties">
27792753used must be already defined by the time the regular expression is
27802754compiled (but note that this construct can be used instead of such
27812755properties).
27822756
27832757=end original
27842758
27852759使用される
27862760L<ユーザー定義特性|perlunicode/"User-Defined Character Properties"> は、
27872761正規表現がコンパイルされるときにすでに定義されている必要があります
27882762(ただし、このような特性の代わりにこの構文を使用することもできます)。
27892763
27902764=item 3
27912765
27922766=begin original
27932767
27942768A regular expression that otherwise would compile
27952769using C<E<sol>d> rules, and which uses this construct will instead
27962770use C<E<sol>u>. Thus this construct tells Perl that you don't want
27972771C<E<sol>d> rules for the entire regular expression containing it.
27982772
27992773=end original
28002774
28012775C<E<sol>d> 規則を使用してコンパイルされ、この構文を使用する正規表現は、
28022776代わりに C<E<sol>u> を使用します。
28032777したがって、この構文は、C<E<sol>d> 規則が含まれている
28042778正規表現全体に対して C<E<sol>d> 規則が必要ないことを Perl に通知します。
28052779
28062780=back
28072781
28082782=begin original
28092783
28102784Note that skipping white space applies only to the interior of this
28112785construct. There must not be any space between any of the characters
28122786that form the initial C<(?[>. Nor may there be space between the
28132787closing C<])> characters.
28142788
28152789=end original
28162790
28172791空白のスキップは、この構造体の内部にのみ適用されることに注意してください。
28182792最初の C<(?[> を形成する文字の間に空白を入れることはできません。
28192793また、終わりの C<])> 文字の間に空白を入れることもできません。
28202794
28212795=begin original
28222796
28232797Just as in all regular expressions, the pattern can be built up by
28242798including variables that are interpolated at regex compilation time.
2825But its best to compile each sub-component.
2799Care must be taken to ensure that you are getting what you expect. For
2800example:
28262801
28272802=end original
28282803
28292804すべての正規表現と同様に、正規表現コンパイル時に補完される変数を
28302805含めることでパターンを構築できます。
2831しかし部分要素毎にコンパイルするのが最善です。
2806期待どおり結果得られるように注意が必要です。
2832
2833 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2834 my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
2835
2836=begin original
2837
2838When these are embedded in another pattern, what they match does not
2839change, regardless of parenthesization or what modifiers are in effect
2840in that outer pattern. If you fail to compile the subcomponents, you
2841can get some nasty surprises. For example:
2842
2843=end original
2844
2845これらが別のパターンに埋め込まれている場合、親子関係やその外側のパターンで
2846有効な修飾子に関係なく、一致するものは変わりません。
2847部分要素をコンパイルするのに失敗すると、扱いにくい驚きを受けることに
2848なるかもしれません。
28492807例えば:
28502808
28512809 my $thai_or_lao = '\p{Thai} + \p{Lao}';
28522810 ...
28532811 qr/(?[ \p{Digit} & $thai_or_lao ])/;
28542812
28552813=begin original
28562814
28572815compiles to
28582816
28592817=end original
28602818
28612819これは次のようにコンパイルされます:
28622820
28632821 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
28642822
28652823=begin original
28662824
2867But this does not have the effect that someone reading the source code
2825But this does not have the effect that someone reading the code would
2868would likely expect, as the intersection applies just to C<\p{Thai}>,
2826likely expect, as the intersection applies just to C<\p{Thai}>,
2869excluding the Laotian. Its best to compile the subcomponents, but you
2827excluding the Laotian. Pitfalls like this can be avoided by
2870could also parenthesize the component pieces:
2828parenthesizing the component pieces:
28712829
28722830=end original
28732831
2874しかし、これは、ソースコードを読んでいる人が期待するような効果はありません;
2832しかし、これは、コードを読んでいる人が期待するような効果はありません;
28752833なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
28762834適用されないからです。
2877部分要素毎にコンパイルするのが最善ですが、
2835このような落とし穴は、コンポーネントをかっこ囲むことで回避できま:
2878要素をかっこで囲むことでも回避できます:
28792836
28802837 my $thai_or_lao = '( \p{Thai} + \p{Lao} )';
28812838
28822839=begin original
28832840
28842841But any modifiers will still apply to all the components:
28852842
28862843=end original
28872844
28882845ただし、修飾子はすべてのコンポーネントに適用されます:
28892846
28902847 my $lower = '\p{Lower} + \p{Digit}';
28912848 qr/(?[ \p{Greek} & $lower ])/i;
28922849
28932850=begin original
28942851
2895matches upper case things. So just, compile the subcomponents, as
2852matches upper case things. You can avoid surprises by making the
2896illustrated above.
2853components into instances of this construct by compiling them:
28972854
28982855=end original
28992856
29002857これは大文字のものと一致します。
2901従って、既に示したように、単に部分要素をコンパイルしてください。
2858コンポーネントをコンパイルしてこの構文の実体にすることで、
2859予期せぬ事態を避けることができます:
2860
2861 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2862 my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
2863
2864=begin original
2865
2866When these are embedded in another pattern, what they match does not
2867change, regardless of parenthesization or what modifiers are in effect
2868in that outer pattern.
2869
2870=end original
2871
2872これらが別のパターンに埋め込まれている場合、親子関係やその外側のパターンで
2873有効な修飾子に関係なく、一致するものは変わりません。
29022874
29032875=begin original
29042876
29052877Due to the way that Perl parses things, your parentheses and brackets
29062878may need to be balanced, even including comments. If you run into any
29072879examples, please send them to C<perlbug@perl.org>, so that we can have a
29082880concrete example for this man page.
29092881
29102882=end original
29112883
29122884Perl の構文解析方法によっては、コメントを含めてもかっこと大かっこの
29132885バランスを取る必要がある場合があります。
29142886もし何か例を見つけたら、C<perlbug@perl.org> まで送ってください。
29152887そうすれば、この man ページの具体的な例を得ることができます。
29162888
29172889=begin original
29182890
29192891We may change it so that things that remain legal uses in normal bracketed
29202892character classes might become illegal within this experimental
29212893construct. One proposal, for example, is to forbid adjacent uses of the
29222894same character, as in C<(?[ [aa] ])>. The motivation for such a change
29232895is that this usage is likely a typo, as the second "a" adds nothing.
29242896
29252897=end original
29262898
29272899たとえば、C<(?[ [aa] ])> のように、同じ文字を隣接して使用すること
29282900を禁止することが提案されています。
29292901このような変更の動機は、2 番目の "a" は何も追加しないので、この使用は
29302902タイプミスである可能性が高いということです。
29312903
29322904=begin meta
29332905
29342906Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1-)
29352907Status: completed
29362908
29372909=end meta