perlrecharclass > 5.36.0 との差分

perlrecharclass 5.36.0 と 5.22.1 の差分

11
2=encoding utf8
2=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
76add matching the newline by using the I<single line> modifier:
76add matching the newline by using the I<single line> modifier: either
7777for the entire regular expression with the C</s> modifier, or
78locally with C<(?s)> (and even globally within the scope of
78locally with C<(?s)>. (The C<L</\N>> backslash sequence, described
79L<C<use re '/s'>|re/'E<sol>flags' mode>). (The C<L</\N>> backslash
80sequence, described
8179below, matches any character except newline without regard to the
8280I<single line> modifier.)
8381
8482=end original
8583
8684ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に
8785もっともよく知られている文字クラスです。
8886デフォルトでは、ドットは改行を除く任意の文字にマッチングします。
8987このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
9088変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには
91C<(?s)> を使います
89C<(?s)> を使います
92(そしてグローバルに L<C<use re '/s'>|re/'E<sol>flags' mode> の
93スコープ内の場合でもそうです)。
9490(後述する C<L</\N>> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
9591関わりなく改行以外の任意の文字にマッチングします。)
9692
9793=begin original
9894
9995Here are some examples:
10096
10197=end original
10298
10399以下は例です:
104100
105101=begin original
106102
107103 "a" =~ /./ # Match
108104 "." =~ /./ # Match
109105 "" =~ /./ # No match (dot has to match a character)
110106 "\n" =~ /./ # No match (dot does not match a newline)
111107 "\n" =~ /./s # Match (global 'single line' modifier)
112108 "\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
113109 "ab" =~ /^.$/ # No match (dot matches one character)
114110
115111=end original
116112
117113 "a" =~ /./ # マッチングする
118114 "." =~ /./ # マッチングする
119115 "" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
120116 "\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
121117 "\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
122118 "\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
123119 "ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
124120
125121=head2 Backslash sequences
126122X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
127123X<\N> X<\v> X<\V> X<\h> X<\H>
128124X<word> X<whitespace>
129125
130126(逆スラッシュシーケンス)
131127
132128=begin original
133129
134130A backslash sequence is a sequence of characters, the first one of which is a
135131backslash. Perl ascribes special meaning to many such sequences, and some of
136132these are character classes. That is, they match a single character each,
137133provided that the character belongs to the specific set of characters defined
138134by the sequence.
139135
140136=end original
141137
142138逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。
143139Perl はそのような並びの多くに特別な意味を持たせていて、
144140その一部は文字クラスです。
145141つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に
146142帰属する一文字にマッチングします。
147143
148144=begin original
149145
150146Here's a list of the backslash sequences that are character classes. They
151147are discussed in more detail below. (For the backslash sequences that aren't
152148character classes, see L<perlrebackslash>.)
153149
154150=end original
155151
156152以下は文字クラスの逆スラッシュシーケンスの一覧です。
157153以下でさらに詳細に議論します。
158154(文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を
159155参照してください。)
160156
161157=begin original
162158
163159 \d Match a decimal digit character.
164160 \D Match a non-decimal-digit character.
165161 \w Match a "word" character.
166162 \W Match a non-"word" character.
167163 \s Match a whitespace character.
168164 \S Match a non-whitespace character.
169165 \h Match a horizontal whitespace character.
170166 \H Match a character that isn't horizontal whitespace.
171167 \v Match a vertical whitespace character.
172168 \V Match a character that isn't vertical whitespace.
173169 \N Match a character that isn't a newline.
174170 \pP, \p{Prop} Match a character that has the given Unicode property.
175171 \PP, \P{Prop} Match a character that doesn't have the Unicode property
176172
177173=end original
178174
179175 \d 10 進数字にマッチング。
180176 \D 非 10 進数字にマッチング。
181177 \w 「単語」文字にマッチング。
182178 \W 非「単語」文字にマッチング。
183179 \s 空白文字にマッチング。
184180 \S 非空白文字にマッチング。
185181 \h 水平空白文字にマッチング。
186182 \H 水平空白でない文字にマッチング。
187183 \v 垂直空白文字にマッチング。
188184 \V 垂直空白でない文字にマッチング。
189185 \N 改行以外の文字にマッチング。
190186 \pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
191187 \PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
192188
193189=head3 \N
194190
195191=begin original
196192
197193C<\N>, available starting in v5.12, like the dot, matches any
198194character that is not a newline. The difference is that C<\N> is not influenced
199195by the I<single line> regular expression modifier (see L</The dot> above). Note
200196that the form C<\N{...}> may mean something completely different. When the
201197C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
202198character that many times. For example, C<\N{3}> means to match 3
203199non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}>
204200is not a legal quantifier, it is presumed to be a named character. See
205201L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and
206202C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
207203names are respectively C<COLON>, C<4F>, and C<F4>.
208204
209205=end original
210206
211207v5.12 から利用可能な C<\N> は、ドットのように、
212208改行以外の任意の文字にマッチングします。
213209違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです
214210(上述の L</The dot> 参照)。
215211C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに
216212注意してください。
217213C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の
218214非改行文字にマッチングします。
219215例えば、C<\N{3}> は三つの非改行にマッチングします;
220216C<\N{5,}> は五つ以上の非改行にマッチングします。
221217しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と
222218推定されます。
223219これについては L<charnames> を参照してください。
224220例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な
225221量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の
226222文字を探そうとします。
227223
228224=head3 Digits
229225
230226(数字)
231227
232228=begin original
233229
234230C<\d> matches a single character considered to be a decimal I<digit>.
235231If the C</a> regular expression modifier is in effect, it matches [0-9].
236232Otherwise, it
237233matches anything that is matched by C<\p{Digit}>, which includes [0-9].
238234(An unlikely possible exception is that under locale matching rules, the
239235current locale might not have C<[0-9]> matched by C<\d>, and/or might match
240236other characters whose code point is less than 256. The only such locale
241237definitions that are legal would be to match C<[0-9]> plus another set of
24223810 consecutive digit characters; anything else would be in violation of
243239the C language standard, but Perl doesn't currently assume anything in
244240regard to this.)
245241
246242=end original
247243
248244C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。
249245C</a> 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。
250246さもなければ、これは C<[0-9]> を含む、C<\p{Digit}> にマッチングするものに
251247マッチングします。
252248(ありそうもない例外はロケールマッチングの下で、現在のロケールが
253249C<\d> にマッチングする [0-9] がないか、
254250符号位置が 256 未満の他の文字にマッチングすることです。
255251唯一正当なロケール定義は、C<[0-9]> に加えてもう一つの 10 の連続した
256252数字の集合にマッチングするもので、
257253それ以外は C 言語標準に違反していますが、
258254Perl は今のところこれに関して何も仮定しません。)
259255
260256=begin original
261257
262258What this means is that unless the C</a> modifier is in effect C<\d> not
263259only matches the digits '0' - '9', but also Arabic, Devanagari, and
264260digits from other languages. This may cause some confusion, and some
265261security issues.
266262
267263=end original
268264
269265これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字
270266'0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の
271267数字もマッチングします。
272268これは混乱やセキュリティ問題を引き起こすことがあります。
273269
274270=begin original
275271
276272Some digits that C<\d> matches look like some of the [0-9] ones, but
277273have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks
278very much like an ASCII DIGIT EIGHT (U+0038), and LEPCHA DIGIT SIX
274very 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
281275is expecting only the ASCII digits might be misled, or if the match is
282276C<\d+>, the matched string might contain a mixture of digits from
283277different writing systems that look like they signify a number different
284278than they actually do. L<Unicode::UCD/num()> can
285279be used to safely
286280calculate the value, returning C<undef> if the input string contains
287such a mixture. Otherwise, for example, a displayed price might be
281such a mixture.
288deliberately different than it appears.
289282
290283=end original
291284
292285C<\d> にマッチングする数字には、[0-9] のように見えるけれども、
293286異なる値を持つものもあります。
294例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038)
287例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038)
295とてもよく似ていて、
296LEPCHA DIGIT SIX (U+1C46) は ASCII DIGIT FIVE (U+0035) に
297288とてもよく似ています。
298289ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、
299290マッチングが C<\d+> の場合、
300291マッチングした文字列は、実際と異なる値を示しているように見える、
301292異なった書記体系からの数字が混ざったものかもしれません。
302293L<Unicode::UCD/num()> は値を安全に計算するのに使えます;
303294入力文字列がこのような混合を含んでいる場合は C<undef> を返します。
304さもなければ、例えば、表示された価格は見た目と意図的に違うものに
305なるかもしれません。
306295
307296=begin original
308297
309298What C<\p{Digit}> means (and hence C<\d> except under the C</a>
310299modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
311300C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this
312301is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
313302But Unicode also has a different property with a similar name,
314303C<\p{Numeric_Type=Digit}>, which matches a completely different set of
315304characters. These characters are things such as C<CIRCLED DIGIT ONE>
316305or subscripts, or are from writing systems that lack all ten digits.
317306
318307=end original
319308
320309C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、
321310C<\p{General_Category=Decimal_Number}>、または同義語として
322311C<\p{General_Category=Digit}> です。
323312Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に
324313マッチングする文字集合と同じです。
325314ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ
326315別の特性もあります; これは完全に異なる文字集合とマッチングします。
327316これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、
32831710 の数字すべてが揃っていない書記体系からのものです。
329318
330319=begin original
331320
332321The design intent is for C<\d> to exactly match the set of characters
333322that can safely be used with "normal" big-endian positional decimal
334323syntax, where, for example 123 means one 'hundred', plus two 'tens',
335324plus three 'ones'. This positional notation does not necessarily apply
336325to characters that match the other type of "digit",
337326C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
338327
339328=end original
340329
341330設計意図は、C<\d> が「通常の」ビッグエンディアンの
342331位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を
343332加えたものを意味する) で安全に使用できる文字集合と
344正確にマッチングするようにすることです
333正確にマッチングするようにすることです;
345334この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に
346335マッチングする文字には必ずしも適用されないため、
347336C<\d> はこれらの文字にマッチングしません。
348337
349338=begin original
350339
351340The Tamil digits (U+0BE6 - U+0BEF) can also legally be
352341used in old-style Tamil numbers in which they would appear no more than
353342one in a row, separated by characters that mean "times 10", "times 100",
354etc. (See L<https://www.unicode.org/notes/tn21>.)
343etc. (See L<http://www.unicode.org/notes/tn21>.)
355344
356345=end original
357346
358347タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の
359348数字でも合法的に使用することができます;
360349この数字は、「×10」や「×100」などを意味する文字で区切られて、
3613501 回に一度にしか現れません。
362(L<https://www.unicode.org/notes/tn21>を参照してください)
351(L<http://www.unicode.org/notes/tn21>を参照してください)
363352
364353=begin original
365354
366355Any character not matched by C<\d> is matched by C<\D>.
367356
368357=end original
369358
370359C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。
371360
372361=head3 Word characters
373362
374363(単語文字)
375364
376365=begin original
377366
378367A C<\w> matches a single alphanumeric character (an alphabetic character, or a
379368decimal digit); or a connecting punctuation character, such as an
380369underscore ("_"); or a "mark" character (like some sort of accent) that
381370attaches to one of those. It does not match a whole word. To match a
382371whole word, use C<\w+>. This isn't the same thing as matching an
383372English word, but in the ASCII range it is the same as a string of
384373Perl-identifier characters.
385374
386375=end original
387376
388377C<\w> は単語全体ではなく、単一の英数字(つまり英字または数字)または
389378下線(C<_>) のような接続句読点
390379またはこれらの一つに付いている(ある種のアクセントのような)「マーク」文字に
391380マッチングします。
392381これは単語全体にはマッチングしません。
393382単語全体にマッチングするには、C<\w+> を使ってください。
394383これは英語の単語にマッチングするのと同じことではありませんが、
395384ASCII の範囲では、Perl の識別子文字の文字列と同じです。
396385
397386=over
398387
399388=item If the C</a> modifier is in effect ...
400389
401390(C</a> 修飾子が有効なら ...)
402391
403392=begin original
404393
405394C<\w> matches the 63 characters [a-zA-Z0-9_].
406395
407396=end original
408397
409398C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。
410399
411400=item otherwise ...
412401
413402(さもなければ ...)
414403
415404=over
416405
417406=item For code points above 255 ...
418407
419408(256 以上の符号位置では ...)
420409
421410=begin original
422411
423412C<\w> matches the same as C<\p{Word}> matches in this range. That is,
424413it matches Thai letters, Greek letters, etc. This includes connector
425414punctuation (like the underscore) which connect two words together, or
426415diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
427416are generally used to add auxiliary markings to letters.
428417
429418=end original
430419
431420C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに
432421マッチングします。
433422つまり、タイ文字、ギリシャ文字などです。
434423これには(下線のような)二つの単語を繋ぐ接続句読点、
435424C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために
436425使われる修飾字のようなダイアクリティカルマークが含まれます。
437426
438427=item For code points below 256 ...
439428
440429(255 以下の符号位置では ...)
441430
442431=over
443432
444433=item if locale rules are in effect ...
445434
446435(ロケール規則が有効なら ...)
447436
448437=begin original
449438
450439C<\w> matches the platform's native underscore character plus whatever
451440the locale considers to be alphanumeric.
452441
453442=end original
454443
455444C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と
456445考えるものにマッチングします。
457446
458=item if, instead, Unicode rules are in effect ...
447=item if Unicode rules are in effect ...
459448
460(そうではなく、Unicode 規則が有効なら ...)
449(Unicode 規則が有効なら ...)
461450
462451=begin original
463452
464453C<\w> matches exactly what C<\p{Word}> matches.
465454
466455=end original
467456
468457C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。
469458
470459=item otherwise ...
471460
472461(さもなければ ...)
473462
474463=begin original
475464
476465C<\w> matches [a-zA-Z0-9_].
477466
478467=end original
479468
480469C<\w> は [a-zA-Z0-9_] にマッチングします。
481470
482471=back
483472
484473=back
485474
486475=back
487476
488477=begin original
489478
490479Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
491480
492481=end original
493482
494483どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
495484記述されている方法で決定されます。
496485
497486=begin original
498487
499488There are a number of security issues with the full Unicode list of word
500489characters. See L<http://unicode.org/reports/tr36>.
501490
502491=end original
503492
504493完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。
505494L<http://unicode.org/reports/tr36> を参照してください。
506495
507496=begin original
508497
509498Also, for a somewhat finer-grained set of characters that are in programming
510499language identifiers beyond the ASCII range, you may wish to instead use the
511500more customized L</Unicode Properties>, C<\p{ID_Start}>,
512501C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See
513502L<http://unicode.org/reports/tr31>.
514503
515504=end original
516505
517506また、ASCII の範囲を超えたプログラミング言語識別子のための
518507より高精度の文字集合のためには、代わりによりカスタマイズされた
519508L<Unicode 特性|/Unicode Properties>である
520509 C<\p{ID_Start}>,
521510C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を
522511使った方がよいでしょう。
523512L<http://unicode.org/reports/tr31> を参照してください。
524513
525514=begin original
526515
527516Any character not matched by C<\w> is matched by C<\W>.
528517
529518=end original
530519
531520C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。
532521
533522=head3 Whitespace
534523
535524(空白)
536525
537526=begin original
538527
539528C<\s> matches any single character considered whitespace.
540529
541530=end original
542531
543532C<\s> は空白と考えられる単一の文字にマッチングします。
544533
545534=over
546535
547536=item If the C</a> modifier is in effect ...
548537
549538(C</a> 修飾子が有効なら ...)
550539
551540=begin original
552541
553542In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that
554543is, the horizontal tab,
555544the newline, the form feed, the carriage return, and the space.
556545Starting in Perl v5.18, it also matches the vertical tab, C<\cK>.
557546See note C<[1]> below for a discussion of this.
558547
559548=end original
560549
561550全ての Perl バージョンで、C<\s> は [\t\n\f\r ] の 5 文字にマッチングします;
562551つまり、水平タブ、改行、改頁、復帰、スペースです。
563552Perl 5.18 から、垂直タブ C<\cK> にもマッチングします。
564553ここでの議論については後述する C<[1]> を参照してください。
565554
566555=item otherwise ...
567556
568557(さもなければ ...)
569558
570559=over
571560
572561=item For code points above 255 ...
573562
574563(256 以上の符号位置では ...)
575564
576565=begin original
577566
578567C<\s> matches exactly the code points above 255 shown with an "s" column
579568in the table below.
580569
581570=end original
582571
583572C<\s> は、後述する表の "s" の列で示されている、
584573255 を超える符号位置に正確にマッチングします。
585574
586575=item For code points below 256 ...
587576
588577(255 以下の符号位置では ...)
589578
590579=over
591580
592581=item if locale rules are in effect ...
593582
594583(ロケール規則が有効なら ...)
595584
596585=begin original
597586
598587C<\s> matches whatever the locale considers to be whitespace.
599588
600589=end original
601590
602591C<\s> はロケールが空白だと考えるものにマッチングします。
603592
604=item if, instead, Unicode rules are in effect ...
593=item if Unicode rules are in effect ...
605594
606(そうではなく、Unicode 規則が有効なら ...)
595(Unicode 規則が有効なら ...)
607596
608597=begin original
609598
610599C<\s> matches exactly the characters shown with an "s" column in the
611600table below.
612601
613602=end original
614603
615604C<\s> は正確に以下の表で "s" の列にある文字にマッチングします。
616605
617606=item otherwise ...
618607
619608(さもなければ ...)
620609
621610=begin original
622611
623612C<\s> matches [\t\n\f\r ] and, starting in Perl
624613v5.18, the vertical tab, C<\cK>.
625614(See note C<[1]> below for a discussion of this.)
626615Note that this list doesn't include the non-breaking space.
627616
628617=end original
629618
630619C<\s> は [\t\n\f\r ] にマッチングし、Perl v5.18 から、
631620垂直タブ C<\cK> にもマッチングします。
632621(これの議論については後述する C<[1]> を参照してください。)
633622この一覧にはノーブレークスペースが含まれていないことに注意してください。
634623
635624=back
636625
637626=back
638627
639628=back
640629
641630=begin original
642631
643632Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
644633
645634=end original
646635
647636どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
648637記述されている方法で決定されます。
649638
650639=begin original
651640
652641Any character not matched by C<\s> is matched by C<\S>.
653642
654643=end original
655644
656645C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。
657646
658647=begin original
659648
660649C<\h> matches any character considered horizontal whitespace;
661650this includes the platform's space and tab characters and several others
662651listed in the table below. C<\H> matches any character
663652not considered horizontal whitespace. They use the platform's native
664653character set, and do not consider any locale that may otherwise be in
665654use.
666655
667656=end original
668657
669658C<\h> は水平空白と考えられる任意の文字にマッチングします; これは
670659プラットフォームのスペースとタブ文字および以下の表に上げられている
671660いくつかのその他の文字です。
672661C<\H> は水平空白と考えられない文字にマッチングします。
673662これらはプラットフォームのネイティブな文字集合を使い、
674663他の場所では有効なロケールを考慮しません。
675664
676665=begin original
677666
678667C<\v> matches any character considered vertical whitespace;
679668this includes the platform's carriage return and line feed characters (newline)
680669plus several other characters, all listed in the table below.
681670C<\V> matches any character not considered vertical whitespace.
682671They use the platform's native character set, and do not consider any
683672locale that may otherwise be in use.
684673
685674=end original
686675
687676C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは
688677プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です;
689678全ては以下の表に挙げられています。
690679C<\V> は垂直空白と考えられない任意の文字にマッチングします。
691680これらはプラットフォームのネイティブな文字集合を使い、
692681他の場所では有効なロケールを考慮しません。
693682
694683=begin original
695684
696685C<\R> matches anything that can be considered a newline under Unicode
697686rules. It can match a multi-character sequence. It cannot be used inside
698687a bracketed character class; use C<\v> instead (vertical whitespace).
699688It uses the platform's
700689native character set, and does not consider any locale that may
701690otherwise be in use.
702691Details are discussed in L<perlrebackslash>.
703692
704693=end original
705694
706695C<\R> は Unicode の規則で改行と考えられるものにマッチングします。
707696複数文字の並びにマッチングすることもあります。
708697従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を
709698使ってください。
710699これらはプラットフォームのネイティブな文字集合を使い、
711700他の場所では有効なロケールを考慮しません。
712701詳細は L<perlrebackslash> で議論しています。
713702
714703=begin original
715704
716705Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
717706the same characters, without regard to other factors, such as the active
718707locale or whether the source string is in UTF-8 format.
719708
720709=end original
721710
722711C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の
723712ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず
724713同じ文字にマッチングします。
725714
726715=begin original
727716
728717One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true
729718starting in Perl v5.18, but prior to that, the sole difference was that the
730719vertical tab (C<"\cK">) was not matched by C<\s>.
731720
732721=end original
733722
734723C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。
735724Perl 5.18 からはもちろん正しいです; しかしそれより前では、
736725唯一の違いは、垂直タブ (C<"\xcK">) は C<\s> にマッチングしないということです。
737726
738727=begin original
739728
740729The following table is a complete listing of characters matched by
741C<\s>, C<\h> and C<\v> as of Unicode 14.0.
730C<\s>, C<\h> and C<\v> as of Unicode 6.3.
742731
743732=end original
744733
745以下の表は Unicode 14.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
734以下の表は Unicode 6.3 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
746735完全な一覧です。
747736
748737=begin original
749738
750739The first column gives the Unicode code point of the character (in hex format),
751740the second column gives the (Unicode) name. The third column indicates
752741by which class(es) the character is matched (assuming no locale is in
753742effect that changes the C<\s> matching).
754743
755744=end original
756745
757746最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の)
758747名前です。
7597483 番目の列はどのクラスにマッチングするかを示しています
760749(C<\s> のマッチングを変更するようなロケールが
761750有効でないことを仮定しています)。
762751
763752 0x0009 CHARACTER TABULATION h s
764753 0x000a LINE FEED (LF) vs
765754 0x000b LINE TABULATION vs [1]
766755 0x000c FORM FEED (FF) vs
767756 0x000d CARRIAGE RETURN (CR) vs
768757 0x0020 SPACE h s
769758 0x0085 NEXT LINE (NEL) vs [2]
770759 0x00a0 NO-BREAK SPACE h s [2]
771760 0x1680 OGHAM SPACE MARK h s
772761 0x2000 EN QUAD h s
773762 0x2001 EM QUAD h s
774763 0x2002 EN SPACE h s
775764 0x2003 EM SPACE h s
776765 0x2004 THREE-PER-EM SPACE h s
777766 0x2005 FOUR-PER-EM SPACE h s
778767 0x2006 SIX-PER-EM SPACE h s
779768 0x2007 FIGURE SPACE h s
780769 0x2008 PUNCTUATION SPACE h s
781770 0x2009 THIN SPACE h s
782771 0x200a HAIR SPACE h s
783772 0x2028 LINE SEPARATOR vs
784773 0x2029 PARAGRAPH SEPARATOR vs
785774 0x202f NARROW NO-BREAK SPACE h s
786775 0x205f MEDIUM MATHEMATICAL SPACE h s
787776 0x3000 IDEOGRAPHIC SPACE h s
788777
789778=over 4
790779
791780=item [1]
792781
793782=begin original
794783
795784Prior to Perl v5.18, C<\s> did not match the vertical tab.
796785C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did.
797786
798787=end original
799788
800789Perl v5.18 より前では、C<\s> は垂直タブにマッチングしませんでした。
801790C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的に
802791マッチングしていたものにマッチングします。
803792
804793=item [2]
805794
806795=begin original
807796
808797NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
809798on the rules in effect. See
810799L<the beginning of this section|/Whitespace>.
811800
812801=end original
813802
814803NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に
815804マッチングしたりマッチングしなかったりします。
816805L<the beginning of this section|/Whitespace> を参照してください。
817806
818807=back
819808
820809=head3 Unicode Properties
821810
822811(Unicode 特性)
823812
824813=begin original
825814
826815C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
827816Unicode properties. One letter property names can be used in the C<\pP> form,
828817with the property name following the C<\p>, otherwise, braces are required.
829818When using braces, there is a single form, which is just the property name
830819enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
831820which means to match if the property "name" for the character has that particular
832821"value".
833822For instance, a match for a number can be written as C</\pN/> or as
834823C</\p{Number}/>, or as C</\p{Number=True}/>.
835824Lowercase letters are matched by the property I<Lowercase_Letter> which
836825has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
837826C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
838827(the underscores are optional).
839828C</\pLl/> is valid, but means something different.
840829It matches a two character string: a letter (Unicode property C<\pL>),
841830followed by a lowercase C<l>.
842831
843832=end original
844833
845834C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に
846835マッチングする文字クラスです。
847836一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ
848837中かっこが必要です。
849838中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、
850839C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を
851840持つものにマッチングすることになる複合形式があります。
852841例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または
853842C</\p{Number=True}/> と書けます。
854843小文字は I<LowercaseLetter> 特性にマッチングします; これには
855844I<Ll> と言う短縮形式があります。
856845中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または
857846C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。
858847C</\pLl/> も妥当ですが、違う意味になります。
859848これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて
860849小文字の C<l> です。
861850
862851=begin original
863852
864What a Unicode property matches is never subject to locale rules, and
853If locale rules are not in effect, the use of
865if locale rules are not otherwise in effect, the use of a Unicode
854a Unicode property will force the regular expression into using Unicode
866property will force the regular expression into using Unicode rules, if
855rules, if it isn't already.
867it isn't already.
868856
869857=end original
870858
871Unicode 特性が何にマッチングするかは決してロケールの規則に影響されず、
872859ロケール規則が有効でない場合、Unicode 特性を使うと
873860正規表現に (まだそうでなければ) Unicode 規則を使うように強制します。
874861
875862=begin original
876863
877864Note that almost all properties are immune to case-insensitive matching.
878865That is, adding a C</i> regular expression modifier does not change what
879they match. But there are two sets that are affected. The first set is
866they match. There are two sets that are affected. The first set is
880867C<Uppercase_Letter>,
881868C<Lowercase_Letter>,
882869and C<Titlecase_Letter>,
883870all of which match C<Cased_Letter> under C</i> matching.
884871The second set is
885872C<Uppercase>,
886873C<Lowercase>,
887874and C<Titlecase>,
888875all of which match C<Cased> under C</i> matching.
889876(The difference between these sets is that some things, such as Roman
890877numerals, come in both upper and lower case, so they are C<Cased>, but
891878aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
892879actually C<Letter_Number>s.)
893880This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
894881of which under C</i> match C<PosixAlpha>.
895882
896883=end original
897884
898885ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに
899886注意してください。
900887つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を
901888与えないということです。
902しかし、影響を与える二つの集合があります。
889影響を与える二つの集合があります。
903890一つ目の集合は
904891C<Uppercase_Letter>,
905892C<Lowercase_Letter>,
906893C<Titlecase_Letter> で、全て C</i> マッチングの下で
907894C<Cased_Letter> にマッチングします。
908895二つ目の集合は
909896C<Uppercase>,
910897C<Lowercase>,
911898C<Titlecase> で、全てC</i> マッチングの下で
912899C<Cased> にマッチングします。
913900(これらの集合の違いは、ローマ数字のような一部のものは、
914901大文字と小文字があるので C<Cased> ですが、
915902文字とは扱われないので C<Cased_Letter> ではありません。
916903これらは実際には C<Letter_Number> です。)
917904この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます;
918905これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。
919906
920907=begin original
921908
922909For more details on Unicode properties, see L<perlunicode/Unicode
923910Character Properties>; for a
924911complete list of possible properties, see
925912L<perluniprops/Properties accessible through \p{} and \P{}>,
926913which notes all forms that have C</i> differences.
927914It is also possible to define your own properties. This is discussed in
928915L<perlunicode/User-Defined Character Properties>.
929916
930917=end original
931918
932919Unicode 特性に関するさらなる詳細については、
933920L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な
934921一覧については、C</i> に違いのある全ての形式について記されている
935922L<perluniprops/Properties accessible through \p{} and \P{}> を参照して
936923ください。
937924独自の特性を定義することも可能です。
938925これは L<perlunicode/User-Defined Character Properties> で
939926議論されています。
940927
941928=begin original
942929
943930Unicode properties are defined (surprise!) only on Unicode code points.
944931Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats
945932non-Unicode code points (those above the legal Unicode maximum of
9469330x10FFFF) as if they were typical unassigned Unicode code points.
947934
948935=end original
949936
950937Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ
951938定義されています。
952939v5.20 から、C<\p> と C<\P> に対してマッチングするとき、
953940Perl は
954941非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) を、
955942典型的な未割り当て Unicode 符号位置であるかのように扱います。
956943
957944=begin original
958945
959946Prior to v5.20, Perl raised a warning and made all matches fail on
960947non-Unicode code points. This could be somewhat surprising:
961948
962949=end original
963950
964951v5.20 より前では、非 Unicode 符号位置に対しては全てのマッチングは失敗して、
965952Perl は警告を出していました。
966953これは驚かされるものだったかもしれません。
967954
968955 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails on Perls < v5.20.
969956 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails on Perls
970957 # < v5.20
971958
972959=begin original
973960
974961Even though these two matches might be thought of as complements, until
975962v5.20 they were so only on Unicode code points.
976963
977964=end original
978965
979966これら二つのマッチングは補集合と考えるかもしれませんが、
980967v5.20 まで、これらは Unicode 符号位置だけでした。
981968
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
992969=head4 Examples
993970
994971(例)
995972
996973=begin original
997974
998975 "a" =~ /\w/ # Match, "a" is a 'word' character.
999976 "7" =~ /\w/ # Match, "7" is a 'word' character as well.
1000977 "a" =~ /\d/ # No match, "a" isn't a digit.
1001978 "7" =~ /\d/ # Match, "7" is a digit.
1002979 " " =~ /\s/ # Match, a space is whitespace.
1003980 "a" =~ /\D/ # Match, "a" is a non-digit.
1004981 "7" =~ /\D/ # No match, "7" is not a non-digit.
1005982 " " =~ /\S/ # No match, a space is not non-whitespace.
1006983
1007984=end original
1008985
1009986 "a" =~ /\w/ # マッチング; "a" は「単語」文字。
1010987 "7" =~ /\w/ # マッチング; "7" も「単語」文字。
1011988 "a" =~ /\d/ # マッチングしない; "a" は数字ではない。
1012989 "7" =~ /\d/ # マッチング; "7" は数字。
1013990 " " =~ /\s/ # マッチング; スペースは空白。
1014991 "a" =~ /\D/ # マッチング; "a" は非数字。
1015992 "7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
1016993 " " =~ /\S/ # マッチングしない; スペースは非空白ではない。
1017994
1018995=begin original
1019996
1020997 " " =~ /\h/ # Match, space is horizontal whitespace.
1021998 " " =~ /\v/ # No match, space is not vertical whitespace.
1022999 "\r" =~ /\v/ # Match, a return is vertical whitespace.
10231000
10241001=end original
10251002
10261003 " " =~ /\h/ # マッチング; スペースは水平空白。
10271004 " " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
10281005 "\r" =~ /\v/ # マッチング; 復帰は垂直空白。
10291006
10301007=begin original
10311008
10321009 "a" =~ /\pL/ # Match, "a" is a letter.
10331010 "a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.
10341011
10351012=end original
10361013
10371014 "a" =~ /\pL/ # マッチング; "a" は英字。
10381015 "a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。
10391016
10401017=begin original
10411018
10421019 "\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character
10431020 # 'THAI CHARACTER SO SO', and that's in
10441021 # Thai Unicode class.
10451022 "a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character.
10461023
10471024=end original
10481025
10491026 "\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字
10501027 # 'THAI CHARACTER SO SO' で、これは
10511028 # Thai Unicode クラスにある。
10521029 "a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。
10531030
10541031=begin original
10551032
10561033It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
10571034complete numbers or words. To match a number (that consists of digits),
10581035use C<\d+>; to match a word, use C<\w+>. But be aware of the security
10591036considerations in doing so, as mentioned above.
10601037
10611038=end original
10621039
10631040C<\d>, C<\w> などは数値や単語全体ではなく、1 文字にマッチングすることは
10641041強調する価値があります。
10651042(数字で構成される) 数値 にマッチングするには C<\d+> を使います;
10661043単語にマッチングするには C<\w+> を使います。
10671044しかし前述したように、そうする場合のセキュリティ問題について
10681045注意してください。
10691046
10701047=head2 Bracketed Character Classes
10711048
10721049(かっこ付き文字クラス)
10731050
10741051=begin original
10751052
10761053The third form of character class you can use in Perl regular expressions
10771054is the bracketed character class. In its simplest form, it lists the characters
10781055that may be matched, surrounded by square brackets, like this: C<[aeiou]>.
10791056This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Like the other
10801057character classes, exactly one character is matched.* To match
10811058a longer string consisting of characters mentioned in the character
10821059class, follow the character class with a L<quantifier|perlre/Quantifiers>. For
10831060instance, C<[aeiou]+> matches one or more lowercase English vowels.
10841061
10851062=end original
10861063
10871064Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ文字クラスです。
10881065もっとも単純な形式では、以下のように大かっこの中にマッチングする文字を
10891066リストします: C<[aeiou]>.
10901067これは C<a>, C<e>, C<i>, C<o>, C<u> のどれかにマッチングします。
10911068他の文字クラスと同様、正確に一つの文字にマッチングします。
10921069文字クラスで言及した文字で構成されるより長い文字列にマッチングするには、
10931070文字クラスに L<量指定子|perlre/Quantifiers> を付けます。
10941071例えば、C<[aeiou]+> は一つまたはそれ以上の小文字英語母音に
10951072マッチングします。
10961073
10971074=begin original
10981075
10991076Repeating a character in a character class has no
11001077effect; it's considered to be in the set only once.
11011078
11021079=end original
11031080
11041081文字クラスの中で文字を繰り返しても効果はありません; 一度だけ現れたものと
11051082考えられます。
11061083
11071084=begin original
11081085
11091086Examples:
11101087
11111088=end original
11121089
11131090例:
11141091
11151092=begin original
11161093
11171094 "e" =~ /[aeiou]/ # Match, as "e" is listed in the class.
11181095 "p" =~ /[aeiou]/ # No match, "p" is not listed in the class.
11191096 "ae" =~ /^[aeiou]$/ # No match, a character class only matches
11201097 # a single character.
11211098 "ae" =~ /^[aeiou]+$/ # Match, due to the quantifier.
11221099
11231100=end original
11241101
11251102 "e" =~ /[aeiou]/ # マッチング; "e" はクラスにある。
11261103 "p" =~ /[aeiou]/ # マッチングしない; "p" はクラスにない。
11271104 "ae" =~ /^[aeiou]$/ # マッチングしない; 一つの文字クラスは
11281105 # 一文字だけにマッチングする。
11291106 "ae" =~ /^[aeiou]+$/ # マッチング; 量指定子により。
11301107
11311108 -------
11321109
11331110=begin original
11341111
11351112* There are two exceptions to a bracketed character class matching a
11361113single character only. Each requires special handling by Perl to make
11371114things work:
11381115
11391116=end original
11401117
11411118* 大かっこ文字クラスは単一の文字にのみマッチングするということには
11421119二つの例外があります。
11431120それぞれは Perl がうまく動くために特別な扱いが必要です:
11441121
11451122=over
11461123
11471124=item *
11481125
11491126=begin original
11501127
11511128When the class is to match caselessly under C</i> matching rules, and a
11521129character that is explicitly mentioned inside the class matches a
11531130multiple-character sequence caselessly under Unicode rules, the class
11541131will also match that sequence. For example, Unicode says that the
11551132letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss>
11561133under C</i> rules. Thus,
11571134
11581135=end original
11591136
11601137クラスが C</i> マッチング規則の下で大文字小文字を無視したマッチングを
11611138して、クラスの中で明示的に記述された文字が Unicode の規則の下で複数文字並びに
11621139大文字小文字を無視してマッチングするとき、
11631140そのクラスはその並びにもマッチングします。
11641141例えば、Unicode は文字 C<LATIN SMALL LETTER SHARP S> は C</i> 規則の下では
11651142並び C<ss> にマッチングするとしています。
11661143従って:
11671144
11681145 'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i # Matches
11691146 'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i # Matches
11701147
11711148=begin original
11721149
11731150For this to happen, the class must not be inverted (see L</Negation>)
11741151and the character must be explicitly specified, and not be part of a
11751152multi-character range (not even as one of its endpoints). (L</Character
11761153Ranges> will be explained shortly.) Therefore,
11771154
11781155=end original
11791156
11801157これが起きるためには、
11811158そのクラスは否定 (L</Negation> 参照) ではなく、
11821159その文字は明示的に指定され、複数文字範囲の一部
11831160(たとえその端でも)でない必要があります。
11841161(L</Character Ranges> は短く説明されています。)
11851162従って:
11861163
11871164 'ss' =~ /\A[\0-\x{ff}]\z/ui # Doesn't match
11881165 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui # No match
11891166 'ss' =~ /\A[\xDF-\xDF]\z/ui # Matches on ASCII platforms, since
11901167 # \xDF is LATIN SMALL LETTER SHARP S,
11911168 # and the range is just a single
11921169 # element
11931170
11941171=begin original
11951172
11961173Note that it isn't a good idea to specify these types of ranges anyway.
11971174
11981175=end original
11991176
12001177どちらにしろこれらの種類の範囲を指定するのは良い考えではありません。
12011178
12021179=item *
12031180
12041181=begin original
12051182
12061183Some names known to C<\N{...}> refer to a sequence of multiple characters,
12071184instead of the usual single character. When one of these is included in
12081185the class, the entire sequence is matched. For example,
12091186
12101187=end original
12111188
12121189Some names known to
12131190C<\N{...}> で知られているいくつかの名前は、通常の単一の文字ではなく、
12141191複数の文字の並びを参照します。
12151192その一つがこのクラスに含まれている場合、並び全体がマッチングします。
12161193例えば:
12171194
12181195 "\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}"
12191196 =~ / ^ [\N{TAMIL SYLLABLE KAU}] $ /x;
12201197
12211198=begin original
12221199
12231200matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence
12241201consisting of the two characters matched against. Like the other
12251202instance where a bracketed class can match multiple characters, and for
12261203similar reasons, the class must not be inverted, and the named sequence
12271204may not appear in a range, even one where it is both endpoints. If
1228these happen, it is a fatal error if the character class is within the
1205these happen, it is a fatal error if the character class is within an
1229scope of L<C<use re 'strict>|re/'strict' mode>, or within an extended
1206extended L<C<(?[...])>|/Extended Bracketed Character Classes>
1230L<C<(?[...])>|/Extended Bracketed Character Classes> class; otherwise
1207class; and only the first code point is used (with
1231only the first code point is used (with a C<regexp>-type warning
1208a C<regexp>-type warning raised) otherwise.
1232raised).
12331209
12341210=end original
12351211
12361212これはマッチングします; なぜなら C<\N{TAMIL SYLLABLE KAU}> は
12371213マッチングする二つの文字からなる名前付き並びだからです。
12381214大かっこクラスが複数の文字にマッチングするその他の例と同じように、
12391215そして同様の理由で、クラスは否定できず、
12401216たとえ両端の間であっても名前付き並びは範囲の中には現れません。
12411217これらが起きたとき、文字クラスが
1242L<C<use re 'strict>|re/'strict' mode> のスコープ内か、
12431218拡張された L<C<(?[...])>|/Extended Bracketed Character Classes> クラスの
12441219中の場合には致命的エラーになります;
12451220さもなければ、最初の符号位置のみが使われます
12461221(そして C<regexp> 系の警告が発生します)。
12471222
12481223=back
12491224
12501225=head3 Special Characters Inside a Bracketed Character Class
12511226
12521227(かっこ付き文字クラスの中の特殊文字)
12531228
12541229=begin original
12551230
12561231Most characters that are meta characters in regular expressions (that
12571232is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
12581233their special meaning and can be used inside a character class without
12591234the need to escape them. For instance, C<[()]> matches either an opening
12601235parenthesis, or a closing parenthesis, and the parens inside the character
1261class don't group or capture. Be aware that, unless the pattern is
1236class don't group or capture.
1262evaluated in single-quotish context, variable interpolation will take
1263place before the bracketed class is parsed:
12641237
12651238=end original
12661239
12671240正規表現内でメタ文字(つまり、C<.>, C<*>, C<(> のように特別な意味を持つ
12681241文字)となるほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を
12691242失うので、エスケープする必要はありません。
12701243例えば、C<[()]> は開きかっこまたは閉じかっこにマッチングし、文字クラスの中の
12711244かっこはグループや捕捉にはなりません。
1272パターンがシングルクォート風コンテキストの中で評価されない限り、
1273変数展開は大かっこクラスがパースされる前に行われることに注意してください:
12741245
1275 $, = "\t| ";
1276 $a =~ m'[$,]'; # single-quotish: matches '$' or ','
1277 $a =~ q{[$,]}' # same
1278 $a =~ m/[$,]/; # double-quotish: Because we made an
1279 # assignment to $, above, this now
1280 # matches "\t", "|", or " "
1281
12821246=begin original
12831247
12841248Characters that may carry a special meaning inside a character class are:
12851249C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
12861250escaped with a backslash, although this is sometimes not needed, in which
12871251case the backslash may be omitted.
12881252
12891253=end original
12901254
12911255文字クラスの中でも特別な意味を持つ文字は:
12921256C<\>, C<^>, C<->, C<[>, C<]> で、以下で議論します。
12931257これらは逆スラッシュでエスケープできますが、不要な場合もあり、そのような
12941258場合では逆スラッシュは省略できます。
12951259
12961260=begin original
12971261
12981262The sequence C<\b> is special inside a bracketed character class. While
12991263outside the character class, C<\b> is an assertion indicating a point
13001264that does not have either two word characters or two non-word characters
13011265on either side, inside a bracketed character class, C<\b> matches a
13021266backspace character.
13031267
13041268=end original
13051269
13061270シーケンス C<\b> は大かっこ文字クラスの内側では特別です。
13071271文字クラスの外側では C<\b> 二つの単語文字か二つの非単語文字のどちらかではない
13081272位置を示す表明ですが、大かっこ文字クラスの内側では C<\b> は後退文字に
13091273マッチングします。
13101274
13111275=begin original
13121276
13131277The sequences
13141278C<\a>,
13151279C<\c>,
13161280C<\e>,
13171281C<\f>,
13181282C<\n>,
13191283C<\N{I<NAME>}>,
13201284C<\N{U+I<hex char>}>,
13211285C<\r>,
13221286C<\t>,
13231287and
13241288C<\x>
13251289are also special and have the same meanings as they do outside a
13261290bracketed character class.
13271291
13281292=end original
13291293
13301294並び
13311295C<\a>,
13321296C<\c>,
13331297C<\e>,
13341298C<\f>,
13351299C<\n>,
13361300C<\N{I<NAME>}>,
13371301C<\N{U+I<hex char>}>,
13381302C<\r>,
13391303C<\t>,
13401304C<\x>
13411305も特別で、大かっこ文字クラスの外側と同じ意味を持ちます。
13421306
13431307=begin original
13441308
13451309Also, a backslash followed by two or three octal digits is considered an octal
13461310number.
13471311
13481312=end original
13491313
13501314また、逆スラッシュに引き続いて 2 または 3 桁の 8 進数字があると 8 進数として
13511315扱われます。
13521316
13531317=begin original
13541318
13551319A C<[> is not special inside a character class, unless it's the start of a
13561320POSIX character class (see L</POSIX Character Classes> below). It normally does
13571321not need escaping.
13581322
13591323=end original
13601324
13611325C<[> は、POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
13621326開始でない限りは文字クラスの中では特別ではありません。
13631327これは普通エスケープは不要です。
13641328
13651329=begin original
13661330
13671331A C<]> is normally either the end of a POSIX character class (see
13681332L</POSIX Character Classes> below), or it signals the end of the bracketed
13691333character class. If you want to include a C<]> in the set of characters, you
13701334must generally escape it.
13711335
13721336=end original
13731337
13741338A C<]> は普通は POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
13751339終わりか、大かっこ文字クラスの終了を示すかどちらかです。
13761340文字集合に C<]> を含める必要がある場合、一般的には
13771341エスケープしなければなりません。
13781342
13791343=begin original
13801344
13811345However, if the C<]> is the I<first> (or the second if the first
13821346character is a caret) character of a bracketed character class, it
13831347does not denote the end of the class (as you cannot have an empty class)
13841348and is considered part of the set of characters that can be matched without
13851349escaping.
13861350
13871351=end original
13881352
13891353しかし、C<]> が大かっこ文字クラスの I<最初> (または最初の文字がキャレットなら
139013542 番目) の文字の場合、(空クラスを作ることはできないので)これはクラスの
13911355終了を意味せず、エスケープなしでマッチングできる文字の集合の一部と
13921356考えられます。
13931357
13941358=begin original
13951359
13961360Examples:
13971361
13981362=end original
13991363
14001364例:
14011365
14021366=begin original
14031367
14041368 "+" =~ /[+?*]/ # Match, "+" in a character class is not special.
14051369 "\cH" =~ /[\b]/ # Match, \b inside in a character class
14061370 # is equivalent to a backspace.
14071371 "]" =~ /[][]/ # Match, as the character class contains
14081372 # both [ and ].
14091373 "[]" =~ /[[]]/ # Match, the pattern contains a character class
14101374 # containing just [, and the character class is
14111375 # followed by a ].
14121376
14131377=end original
14141378
14151379 "+" =~ /[+?*]/ # マッチング; 文字クラス内の "+" は特別ではない。
14161380 "\cH" =~ /[\b]/ # マッチング; 文字クラスの内側の \b は後退と
14171381 # 等価。
14181382 "]" =~ /[][]/ # マッチング; 文字クラスに [ と ] の両方を
14191383 # 含んでいる。
14201384 "[]" =~ /[[]]/ # マッチング; パターンは [ だけを含んでいる
14211385 # 文字クラスと、それに引き続く
14221386 # ] からなる。
14231387
1424=head3 Bracketed Character Classes and the C</xx> pattern modifier
1425
1426=begin original
1427
1428Normally SPACE and TAB characters have no special meaning inside a
1429bracketed character class; they are just added to the list of characters
1430matched by the class. But if the L<C</xx>|perlre/E<sol>x and E<sol>xx>
1431pattern modifier is in effect, they are generally ignored and can be
1432added to improve readability. They can't be added in the middle of a
1433single construct:
1434
1435=end original
1436
1437通常、大かっこ文字クラスの内側では SPACE と TAB の文字は
1438特別な意味はありません; これらは単にクラスによってマッチングされる文字の
1439リストに加えられます。
1440しかし、L<C</xx>|perlre/E<sol>x and E<sol>xx> パターン修飾子が有効の場合、
1441これらは一般的に無視されるので、可読性を向上させるために追加できます。
1442これらは単一の構文の中には追加できません:
1443
1444 / [ \x{10 FFFF} ] /xx # WRONG!
1445
1446=begin original
1447
1448The SPACE in the middle of the hex constant is illegal.
1449
1450=end original
1451
145216 進定数の中の SPACE は不正です。
1453
1454=begin original
1455
1456To specify a literal SPACE character, you can escape it with a
1457backslash, like:
1458
1459=end original
1460
1461リテラルな SPACE 文字を指定するには、次のように逆スラッシュで
1462エスケープします:
1463
1464 /[ a e i o u \ ]/xx
1465
1466=begin original
1467
1468This matches the English vowels plus the SPACE character.
1469
1470=end original
1471
1472これは英語の母音と SPACE 文字に一致します。
1473
1474=begin original
1475
1476For clarity, you should already have been using C<\t> to specify a
1477literal tab, and C<\t> is unaffected by C</xx>.
1478
1479=end original
1480
1481確認すると、リテラルなタブのためには既に C<\t> を使っているべきで、
1482C<\t> は C</xx> の影響を受けません。
1483
14841388=head3 Character Ranges
14851389
14861390(文字範囲)
14871391
14881392=begin original
14891393
14901394It is not uncommon to want to match a range of characters. Luckily, instead
14911395of listing all characters in the range, one may use the hyphen (C<->).
14921396If inside a bracketed character class you have two characters separated
14931397by a hyphen, it's treated as if all characters between the two were in
14941398the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]>
14951399matches any lowercase letter from the first half of the ASCII alphabet.
14961400
14971401=end original
14981402
14991403文字のある範囲にマッチングしたいというのは珍しくありません。
15001404幸運なことに、その範囲の文字を全て一覧に書く代わりに、ハイフン (C<->) を
15011405使えます。
15021406大かっこ文字クラスの内側で二つの文字がハイフンで区切られていると、
15031407二つの文字の間の全ての文字がクラスに書かれているかのように扱われます。
15041408例えば、C<[0-9]> は任意の ASCII 数字にマッチングし、C<[a-m]> は
15051409ASCII アルファベットの前半分の小文字にマッチングします。
15061410
15071411=begin original
15081412
15091413Note that the two characters on either side of the hyphen are not
15101414necessarily both letters or both digits. Any character is possible,
15111415although not advisable. C<['-?]> contains a range of characters, but
15121416most people will not know which characters that means. Furthermore,
15131417such ranges may lead to portability problems if the code has to run on
15141418a platform that uses a different character set, such as EBCDIC.
15151419
15161420=end original
15171421
15181422ハイフンのそれぞれの側の二つの文字は両方とも英字であったり両方とも
15191423数字であったりする必要はないことに注意してください。
15201424任意の文字が可能ですが、勧められません。
15211425C<['-?]> は文字の範囲を含みますが、ほとんどの人はどの文字が含まれるか
15221426分かりません。
15231427さらに、このような範囲は、コードが EBCDIC のような異なった文字集合を使う
15241428プラットフォームで実行されると移植性の問題を引き起こします。
15251429
15261430=begin original
15271431
15281432If a hyphen in a character class cannot syntactically be part of a range, for
15291433instance because it is the first or the last character of the character class,
15301434or if it immediately follows a range, the hyphen isn't special, and so is
15311435considered a character to be matched literally. If you want a hyphen in
15321436your set of characters to be matched and its position in the class is such
15331437that it could be considered part of a range, you must escape that hyphen
15341438with a backslash.
15351439
15361440=end original
15371441
15381442例えば文字クラスの最初または最後であったり、範囲の直後のために、文字クラスの
15391443中のハイフンが文法的に範囲の一部となれない場合、ハイフンは特別ではなく、
15401444リテラルにマッチングするべき文字として扱われます。
15411445マッチングする文字の集合にハイフンを入れたいけれどもその位置が範囲の
15421446一部として考えられる場合はハイフンを逆スラッシュで
15431447エスケープしなければなりません。
15441448
15451449=begin original
15461450
15471451Examples:
15481452
15491453=end original
15501454
15511455例:
15521456
15531457=begin original
15541458
15551459 [a-z] # Matches a character that is a lower case ASCII letter.
15561460 [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or
15571461 # the letter 'z'.
15581462 [-z] # Matches either a hyphen ('-') or the letter 'z'.
15591463 [a-f-m] # Matches any letter between 'a' and 'f' (inclusive), the
15601464 # hyphen ('-'), or the letter 'm'.
15611465 ['-?] # Matches any of the characters '()*+,-./0123456789:;<=>?
15621466 # (But not on an EBCDIC platform).
15631467 [\N{APOSTROPHE}-\N{QUESTION MARK}]
15641468 # Matches any of the characters '()*+,-./0123456789:;<=>?
15651469 # even on an EBCDIC platform.
15661470 [\N{U+27}-\N{U+3F}] # Same. (U+27 is "'", and U+3F is "?")
15671471
15681472=end original
15691473
15701474 [a-z] # 小文字 ASCII 英字にマッチング。
15711475 [a-fz] # 'a' から 'f' の英字およびと 'z' の英字に
15721476 # マッチング。
15731477 [-z] # ハイフン ('-') または英字 'z' にマッチング。
15741478 [a-f-m] # 'a' から 'f' の英字、ハイフン ('-')、英字 'm' に
15751479 # マッチング。
15761480 ['-?] # 文字 '()*+,-./0123456789:;<=>? のどれかにマッチング
15771481 # (しかし EBCDIC プラットフォームでは異なります)。
15781482 [\N{APOSTROPHE}-\N{QUESTION MARK}]
15791483 # たとえ EBCDIC プラットフォームでも '()*+,-./0123456789:;<=>?
15801484 # のいずれかの文字にマッチング。
15811485 [\N{U+27}-\N{U+3F}] # 同じ。 (U+27 は "'", U+3F は "?")
15821486
15831487=begin original
15841488
1585As the final two examples above show, you can achieve portability to
1489As the final two examples above show, you can achieve portablity to
15861490non-ASCII platforms by using the C<\N{...}> form for the range
15871491endpoints. These indicate that the specified range is to be interpreted
15881492using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match
15891493C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>,
15901494and C<\N{U+3F}>, whatever the native code point versions for those are.
15911495These are called "Unicode" ranges. If either end is of the C<\N{...}>
15921496form, the range is considered Unicode. A C<regexp> warning is raised
15931497under C<S<"use re 'strict'">> if the other endpoint is specified
15941498non-portably:
15951499
15961500=end original
15971501
15981502前述の最後の二つの例が示すように、範囲の端点に
15991503C<\N{...}> 形式を使用することで、非 ASCII プラットフォームへの
16001504移植性を実現できます。
16011505これらは、指定された範囲が Unicode 値を使用して解釈されることを示しています;
16021506したがって、C<[\N{U+27}-\N{U+3F}]>は、C<\N{U+27}>、C<\N{U+28}>、
16031507C<\N{U+29}>、...、C<\N{U+3D}>、C<\N{U+3E}>、C<\N{U+3F}> に
16041508マッチングすることを意味します;
16051509これらのネイティブ符号位置のバージョンが何であっても一致します。
16061510これらは "Unicode" 範囲と呼ばれます。
16071511いずれかの端点が C<\N{...}> 形式の場合、範囲は Unicode と見なされます。
16081512もう一方の端点が移植性がない形で指定されている場合、
16091513C<S<"use re 'strict'">> の下で C<regexp> 警告が発生します:
16101514
16111515 [\N{U+00}-\x09] # Warning under re 'strict'; \x09 is non-portable
16121516 [\N{U+00}-\t] # No warning;
16131517
16141518=begin original
16151519
16161520Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ...
16171521C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a
16181522mistake so the warning is raised (under C<re 'strict'>) for it.
16191523
16201524=end original
16211525
16221526前述の両方とも文字 C<\N{U+00}> C<\N{U+01}>, ...
16231527C<\N{U+08}>, C<\N{U+09}> にマッチングしますが、
16241528C<\x09> は誤りのように見えるので、
16251529(C<re 'strict'> の下で) 警告が発生します。
16261530
16271531=begin original
16281532
16291533Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any
16301534subranges of these match what an English-only speaker would expect them
16311535to match on any platform. That is, C<[A-Z]> matches the 26 ASCII
16321536uppercase letters;
16331537C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10
16341538digits. Subranges, like C<[h-k]>, match correspondingly, in this case
16351539just the four letters C<"h">, C<"i">, C<"j">, and C<"k">. This is the
16361540natural behavior on ASCII platforms where the code points (ordinal
16371541values) for C<"h"> through C<"k"> are consecutive integers (0x68 through
163815420x6B). But special handling to achieve this may be needed on platforms
16391543with a non-ASCII native character set. For example, on EBCDIC
16401544platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is
164115450x91, and C<"k"> is 0x92. Perl specially treats C<[h-k]> to exclude the
16421546seven code points in the gap: 0x8A through 0x90. This special handling is
16431547only invoked when the range is a subrange of one of the ASCII uppercase,
16441548lowercase, and digit ranges, AND each end of the range is expressed
16451549either as a literal, like C<"A">, or as a named character (C<\N{...}>,
16461550including the C<\N{U+...> form).
16471551
16481552=end original
16491553
16501554Perl はまた、範囲 C<A-Z>、C<a-z>、C<0-9>、およびこれらの部分範囲が、
16511555英語のみの話者が一致すると予想する範囲とどのプラットフォームでも
16521556一致することを保証します。
16531557つまり、C<[A-Z]> はASCII の大文字 26 文字と一致します;
16541558C<[a-z]> は小文字 26 文字と一致します;
16551559C<[0-9]>は 10 の数字と一致します。
16561560C<[h-k]> のような部分範囲もこれに対応して一致します;
16571561この場合、4 文字 C<"h">、C<"i">、C<"j">、C<"k"> だけが一致します。
16581562これは、C<"h"> から C<"k"> までの符号位置(序数値)が連続した
16591563整数(0x68 から 0x6B)である ASCII プラットフォームでの自然な動作です。
16601564しかし、非 ASCII ネイティブ文字集合を持つプラットフォームでは、
16611565これを実現するための特別な処理が必要になるかもしれません。
16621566たとえば、EBCDIC プラットフォームでは、C<"h"> のコードポイントは
166315670x88、C<"i"> は 0x89、C<"j"> は 0x91、C<"k"> は 0x92 です。
16641568Perl は C<[h-k]> を特別に扱い、隙間にある七つの符号位置
16651569(0x8A から 0x90)を除外します。
16661570この特殊処理は、範囲が ASCII の大文字、小文字、数字の範囲の
16671571いずれかの部分範囲であり、範囲の両端が C<"A"> のようなリテラル
16681572または名前付き文字(C<\N{...}>(C<\N{U+...> 形式を含む))として表現されている
16691573場合にのみ呼び出されます。
16701574
16711575=begin original
16721576
16731577EBCDIC Examples:
16741578
16751579=end original
16761580
16771581EBCDIC の例:
16781582
16791583 [i-j] # Matches either "i" or "j"
16801584 [i-\N{LATIN SMALL LETTER J}] # Same
16811585 [i-\N{U+6A}] # Same
16821586 [\N{U+69}-\N{U+6A}] # Same
16831587 [\x{89}-\x{91}] # Matches 0x89 ("i"), 0x8A .. 0x90, 0x91 ("j")
16841588 [i-\x{91}] # Same
16851589 [\x{89}-j] # Same
16861590 [i-J] # Matches, 0x89 ("i") .. 0xC1 ("J"); special
16871591 # handling doesn't apply because range is mixed
16881592 # case
16891593
16901594=head3 Negation
16911595
16921596(否定)
16931597
16941598=begin original
16951599
16961600It is also possible to instead list the characters you do not want to
16971601match. You can do so by using a caret (C<^>) as the first character in the
16981602character class. For instance, C<[^a-z]> matches any character that is not a
16991603lowercase ASCII letter, which therefore includes more than a million
17001604Unicode code points. The class is said to be "negated" or "inverted".
17011605
17021606=end original
17031607
17041608代わりにマッチングしたくない文字の一覧を指定することも可能です。
17051609文字クラスの先頭の文字としてキャレット (C<^>) を使うことで実現します。
17061610例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします;
17071611従って 100 万種類以上の Unicode 符号位置が含まれます。
17081612このクラスは「否定」("negated") や「反転」("inverted")と呼ばれます。
17091613
17101614=begin original
17111615
17121616This syntax make the caret a special character inside a bracketed character
17131617class, but only if it is the first character of the class. So if you want
17141618the caret as one of the characters to match, either escape the caret or
17151619else don't list it first.
17161620
17171621=end original
17181622
17191623この文法はキャレットを大かっこ文字クラスの内側で特別な文字にしますが、
17201624クラスの最初の文字の場合のみです。
17211625それでマッチングしたい文字の一つでキャレットを使いたい場合、キャレットを
17221626エスケープするか、最初以外の位置に書いてください。
17231627
17241628=begin original
17251629
17261630In inverted bracketed character classes, Perl ignores the Unicode rules
17271631that normally say that named sequence, and certain characters should
17281632match a sequence of multiple characters use under caseless C</i>
17291633matching. Following those rules could lead to highly confusing
17301634situations:
17311635
17321636=end original
17331637
17341638否定大かっこ文字クラスでは、通常は大文字小文字を無視した C</i> マッチングの
17351639下では名前空間とある種の文字が複数の文字並びにマッチングするということを
17361640Perl は無視します。
17371641これらの規則に従うととても混乱する状況を引き起こすことになるからです:
17381642
17391643 "ss" =~ /^[^\xDF]+$/ui; # Matches!
17401644
17411645=begin original
17421646
17431647This should match any sequences of characters that aren't C<\xDF> nor
17441648what C<\xDF> matches under C</i>. C<"s"> isn't C<\xDF>, but Unicode
17451649says that C<"ss"> is what C<\xDF> matches under C</i>. So which one
17461650"wins"? Do you fail the match because the string has C<ss> or accept it
17471651because it has an C<s> followed by another C<s>? Perl has chosen the
17481652latter. (See note in L</Bracketed Character Classes> above.)
17491653
17501654=end original
17511655
17521656これは C</i> の下では C<\xDF> または C<\xDF> にマッチングするもの以外の
17531657任意の文字並びにマッチングするべきです。
17541658C<"s"> は C<\xDF> ではありませんが、
17551659C</i> の下では C<"ss"> は C<\xDF> がマッチングするものと Unicode は
17561660言っています。
17571661ではどちらが「勝つ」のでしょうか?
17581662文字列は C<ss> だからマッチングに失敗するのでしょうか、
17591663それともこれは C<s> の後にもう一つの C<s> があるから成功するのでしょうか?
17601664Perl は後者を選択しました。
17611665(前述の L</Bracketed Character Classes> を参照してください。)
17621666
17631667=begin original
17641668
17651669Examples:
17661670
17671671=end original
17681672
17691673例:
17701674
17711675=begin original
17721676
17731677 "e" =~ /[^aeiou]/ # No match, the 'e' is listed.
17741678 "x" =~ /[^aeiou]/ # Match, as 'x' isn't a lowercase vowel.
17751679 "^" =~ /[^^]/ # No match, matches anything that isn't a caret.
17761680 "^" =~ /[x^]/ # Match, caret is not special here.
17771681
17781682=end original
17791683
17801684 "e" =~ /[^aeiou]/ # マッチングしない; 'e' がある。
17811685 "x" =~ /[^aeiou]/ # マッチング; 'x' は小文字の母音ではない。
17821686 "^" =~ /[^^]/ # マッチングしない; キャレット以外全てにマッチング。
17831687 "^" =~ /[x^]/ # マッチング; キャレットはここでは特別ではない。
17841688
17851689=head3 Backslash Sequences
17861690
17871691(逆スラッシュシーケンス)
17881692
17891693=begin original
17901694
17911695You can put any backslash sequence character class (with the exception of
17921696C<\N> and C<\R>) inside a bracketed character class, and it will act just
17931697as if you had put all characters matched by the backslash sequence inside the
17941698character class. For instance, C<[a-f\d]> matches any decimal digit, or any
17951699of the lowercase letters between 'a' and 'f' inclusive.
17961700
17971701=end original
17981702
17991703大かっこ文字クラスの中に(C<\N> と C<\R> を例外として)逆スラッシュシーケンス
18001704文字クラスを置くことができ、逆スラッシュシーケンスにマッチングする全ての
18011705文字を文字クラスの中に置いたかのように動作します。
18021706例えば、C<[a-f\d]> は任意の 10 進数字、あるいは 'a' から 'f' までの小文字に
18031707マッチングします。
18041708
18051709=begin original
18061710
18071711C<\N> within a bracketed character class must be of the forms C<\N{I<name>}>
18081712or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines,
18091713for the same reason that a dot C<.> inside a bracketed character class loses
18101714its special meaning: it matches nearly anything, which generally isn't what you
18111715want to happen.
18121716
18131717=end original
18141718
18151719大かっこ文字クラスの中のドット C<.> が特別な意味を持たないのと同じ理由で、
18161720大かっこ文字クラスの中の C<\N> は C<\N{I<name>}> または
18171721C<\N{U+I<hex char>}> の形式で、かつ非改行マッチング形式でない形でなければ
18181722なりません: これはほとんど何でもマッチングするので、一般的には起こって
18191723欲しいことではありません。
18201724
18211725=begin original
18221726
18231727Examples:
18241728
18251729=end original
18261730
18271731例:
18281732
18291733=begin original
18301734
18311735 /[\p{Thai}\d]/ # Matches a character that is either a Thai
18321736 # character, or a digit.
18331737 /[^\p{Arabic}()]/ # Matches a character that is neither an Arabic
18341738 # character, nor a parenthesis.
18351739
18361740=end original
18371741
18381742 /[\p{Thai}\d]/ # タイ文字または数字の文字に
18391743 # マッチングする。
18401744 /[^\p{Arabic}()]/ # アラビア文字でもかっこでもない文字に
18411745 # マッチングする。
18421746
18431747=begin original
18441748
18451749Backslash sequence character classes cannot form one of the endpoints
18461750of a range. Thus, you can't say:
18471751
18481752=end original
18491753
18501754逆スラッシュシーケンス文字クラスは範囲の端点の一つにはできません。
18511755従って、以下のようにはできません:
18521756
18531757 /[\p{Thai}-\d]/ # Wrong!
18541758
18551759=head3 POSIX Character Classes
18561760X<character class> X<\p> X<\p{}>
18571761X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph>
18581762X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit>
18591763
18601764(POSIX 文字クラス)
18611765
18621766=begin original
18631767
18641768POSIX character classes have the form C<[:class:]>, where I<class> is the
18651769name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear
18661770I<inside> bracketed character classes, and are a convenient and descriptive
18671771way of listing a group of characters.
18681772
18691773=end original
18701774
18711775POSIX 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は
18721776デリミタです。
18731777POSIX 文字クラスは大かっこ文字クラスの I<内側> にのみ現れ、文字のグループを
18741778一覧するのに便利で記述的な方法です。
18751779
18761780=begin original
18771781
18781782Be careful about the syntax,
18791783
18801784=end original
18811785
18821786文法について注意してください、
18831787
18841788 # Correct:
18851789 $string =~ /[[:alpha:]]/
18861790
18871791 # Incorrect (will warn):
18881792 $string =~ /[:alpha:]/
18891793
18901794=begin original
18911795
18921796The latter pattern would be a character class consisting of a colon,
18931797and the letters C<a>, C<l>, C<p> and C<h>.
18941798POSIX character classes can be part of a larger bracketed character class.
18951799For example,
18961800
18971801=end original
18981802
18991803後者のパターンは、コロンおよび C<a>, C<l>, C<p>, C<h> の文字からなる
19001804文字クラスです。
19011805これら文字クラスはより大きな大かっこ文字クラスの一部にできます。
1902例えば:
1806例えば
19031807
19041808 [01[:alpha:]%]
19051809
19061810=begin original
19071811
19081812is valid and matches '0', '1', any alphabetic character, and the percent sign.
19091813
19101814=end original
19111815
19121816これは妥当で、'0'、'1'、任意の英字、パーセントマークにマッチングします。
19131817
19141818=begin original
19151819
19161820Perl recognizes the following POSIX character classes:
19171821
19181822=end original
19191823
19201824Perl は以下の POSIX 文字クラスを認識します:
19211825
19221826=begin original
19231827
1924 alpha Any alphabetical character (e.g., [A-Za-z]).
1828 alpha Any alphabetical character ("[A-Za-z]").
1925 alnum Any alphanumeric character (e.g., [A-Za-z0-9]).
1829 alnum Any alphanumeric character ("[A-Za-z0-9]").
19261830 ascii Any character in the ASCII character set.
19271831 blank A GNU extension, equal to a space or a horizontal tab ("\t").
19281832 cntrl Any control character. See Note [2] below.
1929 digit Any decimal digit (e.g., [0-9]), equivalent to "\d".
1833 digit Any decimal digit ("[0-9]"), equivalent to "\d".
19301834 graph Any printable character, excluding a space. See Note [3] below.
1931 lower Any lowercase character (e.g., [a-z]).
1835 lower Any lowercase character ("[a-z]").
19321836 print Any printable character, including a space. See Note [4] below.
19331837 punct Any graphical character excluding "word" characters. Note [5].
19341838 space Any whitespace character. "\s" including the vertical tab
19351839 ("\cK").
1936 upper Any uppercase character (e.g., [A-Z]).
1840 upper Any uppercase character ("[A-Z]").
1937 word A Perl extension (e.g., [A-Za-z0-9_]), equivalent to "\w".
1841 word A Perl extension ("[A-Za-z0-9_]"), equivalent to "\w".
1938 xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]). Note [7].
1842 xdigit Any hexadecimal digit ("[0-9a-fA-F]").
19391843
19401844=end original
19411845
1942 alpha 任意の英字 (例: [A-Za-z])。
1846 alpha 任意の英字 ("[A-Za-z]")。
1943 alnum 任意の英数字。(例: [A-Za-z0-9])
1847 alnum 任意の英数字。("[A-Za-z0-9]")
19441848 ascii 任意の ASCII 文字集合の文字。
1945 blank GNU 拡張; スペースまたは水平タブ (\t) と同じ。
1849 blank GNU 拡張; スペースまたは水平タブ ("\t") と同じ。
19461850 cntrl 任意の制御文字。後述の [2] 参照。
1947 digit 任意の 10 進数字 (例: [0-9]); "\d" と等価。
1851 digit 任意の 10 進数字 ("[0-9]"); "\d" と等価。
19481852 graph 任意の表示文字; スペースを除く。後述の [3] 参照。
1949 lower 任意の小文字 (例: [a-z])。
1853 lower 任意の小文字 ("[a-z]")。
19501854 print 任意の表示文字; スペースを含む。後述の [4] 参照。
19511855 punct 任意の「単語」文字を除く表示文字。[5] 参照。
19521856 space 任意の空白文字。水平タブ ("\cK") を含む "\s"。
1953 upper 任意の大文字 (例: [A-Z])。
1857 upper 任意の大文字 ("[A-Z]")。
1954 word Perl 拡張 (例: [A-Za-z0-9_]); "\w" と等価。
1858 word Perl 拡張 ("[A-Za-z0-9_]"); "\w" と等価。
1955 xdigit 任意の 16 進文字 (例: [0-9a-fA-F])。[7] 参照
1859 xdigit 任意の 16 進文字 ("[0-9a-fA-F]")。
19561860
19571861=begin original
19581862
19591863Like the L<Unicode properties|/Unicode Properties>, most of the POSIX
19601864properties match the same regardless of whether case-insensitive (C</i>)
19611865matching is in effect or not. The two exceptions are C<[:upper:]> and
19621866C<[:lower:]>. Under C</i>, they each match the union of C<[:upper:]> and
19631867C<[:lower:]>.
19641868
19651869=end original
19661870
19671871L<Unicode properties|/Unicode Properties> と同様、
19681872ほとんどの POSIX 特性は、大文字小文字無視 (C</i>) が有効かどうかに関わらず
19691873同じものにマッチングします。
19701874二つの例外は C<[:upper:]> と C<[:lower:]> です。
19711875C</i> の下では、これらそれぞれ C<[:upper:]> と C<[:lower:]> の和集合に
19721876マッチングします。
19731877
19741878=begin original
19751879
19761880Most POSIX character classes have two Unicode-style C<\p> property
19771881counterparts. (They are not official Unicode properties, but Perl extensions
19781882derived from official Unicode properties.) The table below shows the relation
19791883between POSIX character classes and these counterparts.
19801884
19811885=end original
19821886
19831887ほとんどの POSIX 文字クラスには、対応する二つの Unicode 式の C<\p> 特性が
19841888あります。
19851889(これは公式 Unicode 特性ではなく、公式 Unicode 特性から派生した Perl
19861890エクステンションです。)
19871891以下の表は POSIX 文字クラスと対応するものとの関連を示します。
19881892
19891893=begin original
19901894
19911895One counterpart, in the column labelled "ASCII-range Unicode" in
19921896the table, matches only characters in the ASCII character set.
19931897
19941898=end original
19951899
19961900対応物の一つである、表で "ASCII-range Unicode" と書かれた列のものは、
19971901ASCII 文字集合の文字にのみマッチングします。
19981902
19991903=begin original
20001904
20011905The other counterpart, in the column labelled "Full-range Unicode", matches any
20021906appropriate characters in the full Unicode character set. For example,
20031907C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any
20041908character in the entire Unicode character set considered alphabetic.
20051909An entry in the column labelled "backslash sequence" is a (short)
20061910equivalent.
20071911
20081912=end original
20091913
20101914もう一つの対応物である、"Full-range Unicode" と書かれた列のものは、
20111915Unicode 文字集合全体の中の適切な任意の文字にマッチングします。
20121916例えば、C<\p{Alpha}> は単に ASCII アルファベット文字だけでなく、
20131917Unicode 文字集合全体の中からアルファベットと考えられる任意の文字に
20141918マッチングします。
20151919"backslash sequence" の列は (短い) 同義語です。
20161920
20171921 [[:...:]] ASCII-range Full-range backslash Note
20181922 Unicode Unicode sequence
20191923 -----------------------------------------------------
20201924 alpha \p{PosixAlpha} \p{XPosixAlpha}
20211925 alnum \p{PosixAlnum} \p{XPosixAlnum}
20221926 ascii \p{ASCII}
20231927 blank \p{PosixBlank} \p{XPosixBlank} \h [1]
20241928 or \p{HorizSpace} [1]
20251929 cntrl \p{PosixCntrl} \p{XPosixCntrl} [2]
20261930 digit \p{PosixDigit} \p{XPosixDigit} \d
20271931 graph \p{PosixGraph} \p{XPosixGraph} [3]
20281932 lower \p{PosixLower} \p{XPosixLower}
20291933 print \p{PosixPrint} \p{XPosixPrint} [4]
20301934 punct \p{PosixPunct} \p{XPosixPunct} [5]
20311935 \p{PerlSpace} \p{XPerlSpace} \s [6]
20321936 space \p{PosixSpace} \p{XPosixSpace} [6]
20331937 upper \p{PosixUpper} \p{XPosixUpper}
20341938 word \p{PosixWord} \p{XPosixWord} \w
2035 xdigit \p{PosixXDigit} \p{XPosixXDigit} [7]
1939 xdigit \p{PosixXDigit} \p{XPosixXDigit}
20361940
20371941=over 4
20381942
20391943=item [1]
20401944
20411945=begin original
20421946
20431947C<\p{Blank}> and C<\p{HorizSpace}> are synonyms.
20441948
20451949=end original
20461950
20471951C<\p{Blank}> と C<\p{HorizSpace}> は同義語です。
20481952
20491953=item [2]
20501954
20511955=begin original
20521956
20531957Control characters don't produce output as such, but instead usually control
20541958the terminal somehow: for example, newline and backspace are control characters.
20551959On ASCII platforms, in the ASCII range, characters whose code points are
20561960between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on
20571961EBCDIC platforms, their counterparts are control characters.
20581962
20591963=end original
20601964
20611965制御文字はそれ自体は出力されず、普通は何か端末を制御します: 例えば
20621966改行と後退は制御文字です。
20631967ASCII プラットフォームで、ASCII の範囲では、符号位置が 0 から 31 までの
20641968範囲の文字および 127 (C<DEL>) が制御文字です;
20651969EBCDIC プラットフォームでは、対応するものは制御文字です。
20661970
20671971=item [3]
20681972
20691973=begin original
20701974
20711975Any character that is I<graphical>, that is, visible. This class consists
20721976of all alphanumeric characters and all punctuation characters.
20731977
20741978=end original
20751979
20761980I<graphical>、つまり見える文字。
20771981このクラスは全ての英数字と全ての句読点文字。
20781982
20791983=item [4]
20801984
20811985=begin original
20821986
20831987All printable characters, which is the set of all graphical characters
20841988plus those whitespace characters which are not also controls.
20851989
20861990=end original
20871991
20881992全ての表示可能な文字; 全ての graphical 文字に加えて制御文字でない空白文字。
20891993
20901994=item [5]
20911995
20921996=begin original
20931997
20941998C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all
20951999non-controls, non-alphanumeric, non-space characters:
20962000C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect,
20972001it could alter the behavior of C<[[:punct:]]>).
20982002
20992003=end original
21002004
21012005ASCII の範囲の C<\p{PosixPunct}> と C<[[:punct:]]> は全ての非制御、非英数字、
21022006非空白文字にマッチングします:
21032007C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (しかしロケールが有効なら、
21042008C<[[:punct:]]> の振る舞いが変わります)。
21052009
21062010=begin original
21072011
21082012The similarly named property, C<\p{Punct}>, matches a somewhat different
21092013set in the ASCII range, namely
21102014C<[-!"#%&'()*,./:;?@[\\\]_{}]>. That is, it is missing the nine
21112015characters C<[$+E<lt>=E<gt>^`|~]>.
21122016This is because Unicode splits what POSIX considers to be punctuation into two
21132017categories, Punctuation and Symbols.
21142018
21152019=end original
21162020
21172021似たような名前の特性 C<\p{Punct}> は、ASCII 範囲の異なる集合である
21182022C<[-!"#%&'()*,./:;?@[\\\]_{}]> にマッチングします。
21192023つまり、C<[$+E<lt>=E<gt>^`|~]> の 9 文字はありません。
21202024これは、Unicode は POSIX が句読点と考えるものを二つのカテゴリ
21212025Punctuation と Symbols に分けているからです。
21222026
21232027=begin original
21242028
21252029C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what
21262030C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}>
21272031matches. This is different than strictly matching according to
21282032C<\p{Punct}>. Another way to say it is that
21292033if Unicode rules are in effect, C<[[:punct:]]> matches all characters
21302034that Unicode considers punctuation, plus all ASCII-range characters that
21312035Unicode considers symbols.
21322036
21332037=end original
21342038
21352039C<\p{XPosixPunct}> と (Unicode の規則の下での) C<[[:punct:]]> は、
21362040ASCII の範囲で C<\p{PosixPunct}> がマッチングする物に加えて、
21372041C<\p{Punct}> がマッチングする物にマッチングします。
21382042これは C<\p{Punct}> に従って正確にマッチングする物と異なります。
21392043Unicode 規則が有効な場合のもう一つの言い方は、C<[[:punct:]]> は Unicode が
21402044句読点として扱うものに加えて、Unicode が "symbols" として扱う ASCII 範囲の
21412045全ての文字にマッチングします。
21422046
21432047=item [6]
21442048
21452049=begin original
21462050
21472051C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl
21482052v5.18. In earlier versions, these differ only in that in non-locale
21492053matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>.
21502054Same for the two ASCII-only range forms.
21512055
21522056=end original
21532057
21542058C<\p{XPerlSpace}> と C<\p{Space}> は、Perl v5.18 からは同じように
21552059マッチングします。
21562060以前のバージョンでは、これらの違いは、非ロケールマッチングでは
21572061C<\p{XPerlSpace}> は垂直タブ C<\cK> にもマッチングしないということだけです。
21582062二つの ASCII のみの範囲の形式では同じです。
21592063
2160=item [7]
2161
2162=begin original
2163
2164Unlike C<[[:digit:]]> which matches digits in many writing systems, such
2165as Thai and Devanagari, there are currently only two sets of hexadecimal
2166digits, and it is unlikely that more will be added. This is because you
2167not only need the ten digits, but also the six C<[A-F]> (and C<[a-f]>)
2168to correspond. That means only the Latin script is suitable for these,
2169and Unicode has only two sets of these, the familiar ASCII set, and the
2170fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO).
2171
2172=end original
2173
2174タイ文字やデバナーガリ文字のように多くの書記体系の数字にマッチングする
2175C<[[:digit:]]> と異なり、16 進数の二つの集合だけで、これ以上追加されることは
2176おそらくありません。
2177これは、対応するのに 10 の数字だけでなく、6 個の C<[A-F]> (および C<[a-f]>) も
2178必要だからです。
2179これは、Latin 用字のみがこれらに適合していて、
2180Unicode はこれらの二つの集合、つまり慣れ親しんだ
2181ASCII 集合と、U+FF10 (FULLWIDTH DIGIT ZERO) から始まる全角形式のみを
2182持つということです。
2183
21842064=back
21852065
21862066=begin original
21872067
21882068There are various other synonyms that can be used besides the names
2189listed in the table. For example, C<\p{XPosixAlpha}> can be written as
2069listed in the table. For example, C<\p{PosixAlpha}> can be written as
21902070C<\p{Alpha}>. All are listed in
21912071L<perluniprops/Properties accessible through \p{} and \P{}>.
21922072
21932073=end original
21942074
21952075表に挙げられている名前以外にも様々なその他の同義語が使えます。
2196例えば、C<\p{XPosixAlpha}> は C<\p{Alpha}> と書けます。
2076例えば、C<\p{PosixAlpha}> は C<\p{Alpha}> と書けます。
21972077全ての一覧は
21982078L<perluniprops/Properties accessible through \p{} and \P{}> に
21992079あります。
22002080
22012081=begin original
22022082
22032083Both the C<\p> counterparts always assume Unicode rules are in effect.
22042084On ASCII platforms, this means they assume that the code points from 128
22052085to 255 are Latin-1, and that means that using them under locale rules is
22062086unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the
22072087POSIX character classes are useful under locale rules. They are
22082088affected by the actual rules in effect, as follows:
22092089
22102090=end original
22112091
22122092C<\p> に対応するものの両方は常に Unicode の規則が有効であることを仮定します。
22132093これは、ASCII プラットフォームでは、128 から 255 の符号位置は
22142094Latin-1 であることを仮定するということで、ロケールの規則の下で
22152095これらを使うということは、ロケールが Latin-1 か UTF-8 であることが
22162096補償されていない限り賢明ではないということです。
22172097一方、POSIX 文字クラスはロケールの規則の下で有用です。
22182098これらは次のように、実際に有効な規則に影響を受けます:
22192099
22202100=over
22212101
22222102=item If the C</a> modifier, is in effect ...
22232103
22242104(C</a> が有効なら...)
22252105
22262106=begin original
22272107
22282108Each of the POSIX classes matches exactly the same as their ASCII-range
22292109counterparts.
22302110
22312111=end original
22322112
22332113それぞれの POSIX クラスは ASCII の範囲で対応する正確に同じものに
22342114マッチングします。
22352115
22362116=item otherwise ...
22372117
22382118(さもなければ ...)
22392119
22402120=over
22412121
22422122=item For code points above 255 ...
22432123
22442124(256 以上の符号位置では ...)
22452125
22462126=begin original
22472127
22482128The POSIX class matches the same as its Full-range counterpart.
22492129
22502130=end original
22512131
22522132POSIX クラスはその Full の範囲で対応する同じものにマッチングします。
22532133
22542134=item For code points below 256 ...
22552135
22562136(255 以下の符号位置では ...)
22572137
22582138=over
22592139
22602140=item if locale rules are in effect ...
22612141
22622142(ロケール規則が有効なら ...)
22632143
22642144=begin original
22652145
22662146The POSIX class matches according to the locale, except:
22672147
22682148=end original
22692149
22702150POSIX クラスはロケールに従ってマッチングします; 例外は:
22712151
22722152=over
22732153
22742154=item C<word>
22752155
22762156=begin original
22772157
22782158also includes the platform's native underscore character, no matter what
22792159the locale is.
22802160
22812161=end original
22822162
22832163それに加えて、ロケールが何かに関わらず、プラットフォームのネイティブな
22842164下線文字を使います。
22852165
22862166=item C<ascii>
22872167
22882168=begin original
22892169
22902170on platforms that don't have the POSIX C<ascii> extension, this matches
22912171just the platform's native ASCII-range characters.
22922172
22932173=end original
22942174
22952175POSIX C<ascii> 拡張を持たないプラットフォームでは、
22962176これは単にプラットフォームのネイティブな ASCII の範囲の文字に
22972177マッチングします。
22982178
22992179=item C<blank>
23002180
23012181=begin original
23022182
23032183on platforms that don't have the POSIX C<blank> extension, this matches
23042184just the platform's native tab and space characters.
23052185
23062186=end original
23072187
23082188on platforms that don't have the
23092189POSIX C<blank> 格調を持たないプラットフォームでは、
23102190これは単にプラットフォームのネイティブなタブとすぺーす文字に
23112191マッチングします。
23122192
23132193=back
23142194
2315=item if, instead, Unicode rules are in effect ...
2195=item if Unicode rules are in effect ...
23162196
2317(そうではなく、Unicode 規則が有効なら ...)
2197(Unicode 規則が有効なら ...)
23182198
23192199=begin original
23202200
23212201The POSIX class matches the same as the Full-range counterpart.
23222202
23232203=end original
23242204
23252205POSIX クラスは Full の範囲の対応する同じものにマッチングします。
23262206
23272207=item otherwise ...
23282208
23292209(さもなければ ...)
23302210
23312211=begin original
23322212
23332213The POSIX class matches the same as the ASCII range counterpart.
23342214
23352215=end original
23362216
23372217POSIX クラスは ASCII の範囲の同じものにマッチングします。
23382218
23392219=back
23402220
23412221=back
23422222
23432223=back
23442224
23452225=begin original
23462226
23472227Which rules apply are determined as described in
23482228L<perlre/Which character set modifier is in effect?>.
23492229
23502230=end original
23512231
23522232どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
23532233記述されている方法で決定されます。
23542234
2235=begin original
2236
2237It is proposed to change this behavior in a future release of Perl so that
2238whether or not Unicode rules are in effect would not change the
2239behavior: Outside of locale, the POSIX classes
2240would behave like their ASCII-range counterparts. If you wish to
2241comment on this proposal, send email to C<perl5-porters@perl.org>.
2242
2243=end original
2244
2245Perl の将来のバージョンではこの振る舞いを変えることが提案されています;
2246Unicode の規則が有効かどうかは振る舞いを変えません:
2247ロケールの外側では、
2248POSIX クラスはその ASCII の範囲の対応するものと同様に振る舞います。
2249この提案にコメントしたいなら、C<perl5-porters@perl.org> にメールを
2250送ってください。
2251
23552252=head4 Negation of POSIX character classes
23562253X<character class, negation>
23572254
23582255(POSIX 文字クラスの否定)
23592256
23602257=begin original
23612258
23622259A Perl extension to the POSIX character class is the ability to
23632260negate it. This is done by prefixing the class name with a caret (C<^>).
23642261Some examples:
23652262
23662263=end original
23672264
23682265POSIX 文字クラスに対する Perl の拡張は否定の機能です。
23692266これはクラス名の前にキャレット (C<^>) を置くことで実現します。
23702267いくつかの例です:
23712268
23722269 POSIX ASCII-range Full-range backslash
23732270 Unicode Unicode sequence
23742271 -----------------------------------------------------
23752272 [[:^digit:]] \P{PosixDigit} \P{XPosixDigit} \D
23762273 [[:^space:]] \P{PosixSpace} \P{XPosixSpace}
23772274 \P{PerlSpace} \P{XPerlSpace} \S
23782275 [[:^word:]] \P{PerlWord} \P{XPosixWord} \W
23792276
23802277=begin original
23812278
23822279The backslash sequence can mean either ASCII- or Full-range Unicode,
23832280depending on various factors as described in L<perlre/Which character set modifier is in effect?>.
23842281
23852282=end original
23862283
23872284逆スラッシュシーケンスは ASCII- か Full-range Unicode のどちらかを意味します;
23882285どちらが使われるかは L<perlre/Which character set modifier is in effect?> で
23892286記述されている様々な要素に依存します。
23902287
23912288=head4 [= =] and [. .]
23922289
23932290([= =] と [. .])
23942291
23952292=begin original
23962293
23972294Perl recognizes the POSIX character classes C<[=class=]> and
23982295C<[.class.]>, but does not (yet?) support them. Any attempt to use
23992296either construct raises an exception.
24002297
24012298=end original
24022299
24032300Perl は POSIX 文字クラス C<[=class=]> と C<[.class.]> を認識しますが、
24042301これらには(まだ?)対応していません。
24052302このような構文を使おうとすると例外が発生します。
24062303
24072304=head4 Examples
24082305
24092306(例)
24102307
24112308=begin original
24122309
24132310 /[[:digit:]]/ # Matches a character that is a digit.
24142311 /[01[:lower:]]/ # Matches a character that is either a
24152312 # lowercase letter, or '0' or '1'.
24162313 /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
24172314 # except the letters 'a' to 'f' and 'A' to
24182315 # 'F'. This is because the main character
24192316 # class is composed of two POSIX character
24202317 # classes that are ORed together, one that
24212318 # matches any digit, and the other that
24222319 # matches anything that isn't a hex digit.
24232320 # The OR adds the digits, leaving only the
24242321 # letters 'a' to 'f' and 'A' to 'F' excluded.
24252322
24262323=end original
24272324
24282325 /[[:digit:]]/ # 数字の文字にマッチングする。
24292326 /[01[:lower:]]/ # 小文字、'0'、'1' のいずれかの文字に
24302327 # マッチングする。
24312328 /[[:digit:][:^xdigit:]]/ # 'a' から 'f' と 'A' から 'F' 以外の任意の文字に
24322329 # マッチング。これはメインの文字クラスでは二つの
24332330 # POSIX 文字クラスが OR され、一つは任意の数字に
24342331 # マッチングし、もう一つは 16 進文字でない全ての
24352332 # 文字にマッチングします。OR は数字を加え、
24362333 # 'a' から 'f' および 'A' から 'F' のみが
24372334 # 除外されて残ります。
2335 #
24382336
24392337=head3 Extended Bracketed Character Classes
24402338X<character class>
24412339X<set operations>
24422340
24432341(拡張大かっこ文字クラス)
24442342
24452343=begin original
24462344
24472345This is a fancy bracketed character class that can be used for more
24482346readable and less error-prone classes, and to perform set operations,
24492347such as intersection. An example is
24502348
24512349=end original
24522350
24532351これはしゃれた大かっこ文字クラスで、より読みやすく、エラーが発生しにくい
24542352クラスや、交差などの集合演算を実行するために使用できます。
2455例は:
24562353
24572354 /(?[ \p{Thai} & \p{Digit} ])/
24582355
24592356=begin original
24602357
24612358This will match all the digit characters that are in the Thai script.
24622359
24632360=end original
24642361
24652362これは、タイ語スクリプト内のすべての数字と一致します。
24662363
24672364=begin original
24682365
2469This feature became available in Perl 5.18, as experimental; accepted in
2366This is an experimental feature available starting in 5.18, and is
24705.36.
2367subject to change as we gain field experience with it. Any attempt to
2368use it will raise a warning, unless disabled via
24712369
24722370=end original
24732371
2474の機能Perl 5.18 で実験的に利用可能になりました;
2372は 5.18 から利用きる実験的な機で、現場での経験を積むつれて
24755.36 で受け入られした
2373変更さる可能性があり
2374これを使用しようとすると、次のようにして無効にしない限り、警告が表示されます:
24762375
2376 no warnings "experimental::regex_sets";
2377
24772378=begin original
24782379
2479The rules used by L<C<use re 'strict>|re/'strict' mode> apply to this
2380Comments on this feature are welcome; send email to
2480construct.
2381C<perl5-porters@perl.org>.
24812382
24822383=end original
24832384
2484L<C<use re 'strict>|re/'strict' mode> で使われる規則はこの構文
2385この機能関するコメントを歓迎します。
2485適用れます
2386C<perl5-porters@perl.org> に電子メールを送ってくだ
24862387
24872388=begin original
24882389
24892390We can extend the example above:
24902391
24912392=end original
24922393
24932394上記の例を拡張できます:
24942395
24952396 /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/
24962397
24972398=begin original
24982399
24992400This matches digits that are in either the Thai or Laotian scripts.
25002401
25012402=end original
25022403
25032404これはタイ語またはラオス語のいずれかの数字と一致します。
25042405
25052406=begin original
25062407
25072408Notice the white space in these examples. This construct always has
2508the C<E<sol>xx> modifier turned on within it.
2409the C<E<sol>x> modifier turned on within it.
25092410
25102411=end original
25112412
25122413これらの例の中の空白に注意してください。
2513この構文では、その中では常に C<E<sol>xx> 修飾子がオンになっています。
2414この構文では、その中では常に C<E<sol>x> 修飾子がオンになっています。
25142415
25152416=begin original
25162417
25172418The available binary operators are:
25182419
25192420=end original
25202421
25212422使用可能な 2 項演算子は次のとおりです:
25222423
25232424 & intersection
25242425 + union
25252426 | another name for '+', hence means union
25262427 - subtraction (the result matches the set consisting of those
25272428 code points matched by the first operand, excluding any that
25282429 are also matched by the second operand)
25292430 ^ symmetric difference (the union minus the intersection). This
25302431 is like an exclusive or, in that the result is the set of code
25312432 points that are matched by either, but not both, of the
25322433 operands.
25332434
25342435=begin original
25352436
25362437There is one unary operator:
25372438
25382439=end original
25392440
25402441単項演算子が一つあります。
25412442
25422443 ! complement
25432444
25442445=begin original
25452446
25462447All the binary operators left associate; C<"&"> is higher precedence
25472448than the others, which all have equal precedence. The unary operator
25482449right associates, and has highest precedence. Thus this follows the
25492450normal Perl precedence rules for logical operators. Use parentheses to
25502451override the default precedence and associativity.
25512452
25522453=end original
25532454
25542455すべての二項演算子は左結合です; C<"&"> はその他よりも高い優先順位を持ち、
25552456それ以外は同等の優先順位を持ちます。
25562457単項演算子は右結合で、最も高い優先順位を持ちます。
25572458従って、これは通常の Perl の論理演算子に関する優先順位規則に従います。
25582459デフォルトの優先順位と結合を上書きするにはかっこを使います。
25592460
25602461=begin original
25612462
25622463The main restriction is that everything is a metacharacter. Thus,
25632464you cannot refer to single characters by doing something like this:
25642465
25652466=end original
25662467
25672468主な制限は、すべてがメタ文字であるということです。
25682469したがって、以下のようにして単一文字を参照することはできません:
25692470
25702471 /(?[ a + b ])/ # Syntax error!
25712472
25722473=begin original
25732474
25742475The easiest way to specify an individual typable character is to enclose
25752476it in brackets:
25762477
25772478=end original
25782479
25792480タイプ可能な個々の文字を指定する最も簡単な方法は、次のように
25802481かっこで囲むことです:
25812482
25822483 /(?[ [a] + [b] ])/
25832484
25842485=begin original
25852486
25862487(This is the same thing as C<[ab]>.) You could also have said the
25872488equivalent:
25882489
25892490=end original
25902491
25912492(これはC<[ab]>と同じことです)。
25922493同じことを言うこともできます:
25932494
25942495 /(?[[ a b ]])/
25952496
25962497=begin original
25972498
25982499(You can, of course, specify single characters by using, C<\x{...}>,
25992500C<\N{...}>, etc.)
26002501
26012502=end original
26022503
26032504(もちろん、C<\x{...}> や C<\N{...}> などを使用して 1 文字を
26042505指定することもできます。)
26052506
26062507=begin original
26072508
26082509This last example shows the use of this construct to specify an ordinary
26092510bracketed character class without additional set operations. Note the
2610white space within it. This is allowed because C<E<sol>xx> is
2511white space within it; C<E<sol>x> is turned on even within bracketed
2611automatically turned on within this construct.
2512character classes, except you can't have comments inside them. Hence,
26122513
26132514=end original
26142515
26152516この最後の例では、この構文を使用して、追加の集合操作なしで
26162517通常の大かっこ文字クラスを指定する方法を示しています。
2617この中に空白があることに注意してください
2518この中に空白があることに注意してください;
2618C<E<sol>xx> は、この構自動的に有効になるのでこれが許されます
2519C<E<sol>x> は、かっで囲まれた字クラス内で有効になますが、
2520コメントを含めることはできません。
2521したがって:
26192522
2523 (?[ [#] ])
2524
26202525=begin original
26212526
2527matches the literal character "#". To specify a literal white space character,
2528you can escape it with a backslash, like:
2529
2530=end original
2531
2532は、リテラル文字 "#" にマッチングします。
2533リテラル空白文字を指定するには、次のように逆スラッシュでエスケープします:
2534
2535 /(?[ [ a e i o u \ ] ])/
2536
2537=begin original
2538
2539This matches the English vowels plus the SPACE character.
26222540All the other escapes accepted by normal bracketed character classes are
2623accepted here as well.
2541accepted here as well; but unrecognized escapes that generate warnings
2542in normal classes are fatal errors here.
26242543
26252544=end original
26262545
2546これは英語の母音と SPACE 文字に一致します。
26272547通常の大かっこ文字クラスで受け入れられる他のエスケープは
2628すべてここでも受け入れられます
2548すべてここでも受け入れられますが、通常のクラスで警告を生成する
2549認識されないエスケープはここでは致命的なエラーです。
26292550
26302551=begin original
26312552
2632Because this construct compiles under
2553All warnings from these class elements are fatal, as well as some
2633L<C<use re 'strict>|re/'strict' mode>, unrecognized escapes that
2554practices that don't currently warn. For example you cannot say
2634generate warnings in normal classes are fatal errors here, as well as
2635all other warnings from these class elements, as well as some
2636practices that don't currently warn outside C<re 'strict'>. For example
2637you cannot say
26382555
26392556=end original
26402557
2641この構文は L<C<use re 'strict>|re/'strict' mode> 下でコンパイルされるので、
2558れらクラス要素からすべて警告は致命的あり
2642通常ラスで警告を生成
2559現在警告していないいくつかクティも同様です
2643認識されないエスケープはここでは致命的なエラーです;
2644これらのクラス要素からのその他すべての警告も同様で、
2645C<re 'strict'> の外側では、現在警告していないいくつかのプラクティスも
2646同様です。
26472560例えば次のようにはできません:
26482561
26492562 /(?[ [ \xF ] ])/ # Syntax error!
26502563
26512564=begin original
26522565
26532566You have to have two hex digits after a braceless C<\x> (use a leading
26542567zero to make two). These restrictions are to lower the incidence of
26552568typos causing the class to not match what you thought it would.
26562569
26572570=end original
26582571
26592572中かっこのない C<\x> の後には 2 桁の 16 進数が必要です(2 桁にするには
26602573先頭の 0 を使用します)。
26612574これらの制限は、クラスが想定したものと一致しない原因となる
26622575タイプミスの発生を減らすためです。
26632576
26642577=begin original
26652578
26662579If a regular bracketed character class contains a C<\p{}> or C<\P{}> and
26672580is matched against a non-Unicode code point, a warning may be
26682581raised, as the result is not Unicode-defined. No such warning will come
26692582when using this extended form.
26702583
26712584=end original
26722585
26732586通常の大かっこ文字クラスに C<\p{}> や C<\P{}> が含まれていて、
26742587非 Unicode 符号位置に対してマッチングした場合、
26752588結果は Unicode で定義されていないので、警告が発生します。
26762589このような警告は、拡張形式を使った場合は発生しません。
26772590
26782591=begin original
26792592
26802593The final difference between regular bracketed character classes and
26812594these, is that it is not possible to get these to match a
26822595multi-character fold. Thus,
26832596
26842597=end original
26852598
26862599通常の大かっこ文字クラスとこれらのクラスの最後の違いは、
26872600これらを複数文字畳み込みにマッチングさせることができないということです。
26882601従って:
26892602
26902603 /(?[ [\xDF] ])/iu
26912604
26922605=begin original
26932606
26942607does not match the string C<ss>.
26952608
26962609=end original
26972610
26982611は文字列 C<ss> と一致しません。
26992612
27002613=begin original
27012614
27022615You don't have to enclose POSIX class names inside double brackets,
27032616hence both of the following work:
27042617
27052618=end original
27062619
27072620POSIX クラス名を二重かっこで囲む必要はありません;
27082621そのため、以下の両方とも動作します:
27092622
27102623 /(?[ [:word:] - [:lower:] ])/
27112624 /(?[ [[:word:]] - [[:lower:]] ])/
27122625
27132626=begin original
27142627
27152628Any contained POSIX character classes, including things like C<\w> and C<\D>
27162629respect the C<E<sol>a> (and C<E<sol>aa>) modifiers.
27172630
27182631=end original
27192632
27202633C<\w> や C<\D> などの POSIX 文字クラスは、C<E<sol>a>
27212634(および C<E<sol>aa> )修飾子を尊重します。
27222635
27232636=begin original
27242637
2725Note that C<< (?[ ]) >> is a regex-compile-time construct. Any attempt
2638C<< (?[ ]) >> is a regex-compile-time construct. Any attempt to use
2726to use something which isn't knowable at the time the containing regular
2639something which isn't knowable at the time the containing regular
27272640expression is compiled is a fatal error. In practice, this means
27282641just three limitations:
27292642
27302643=end original
27312644
2732C<< (?[ ]) >> は コンパイル時正規表現構文であることに注意してください
2645C<< (?[ ]) >> は コンパイル時正規表現構文で
27332646正規表現を含むコンパイル時に未知のものを使用しようとすると、
27342647致命的なエラーになります。
27352648実際には、これは三つの制限を意味します:
27362649
27372650=over 4
27382651
27392652=item 1
27402653
27412654=begin original
27422655
2743When compiled within the scope of C<use locale> (or the C<E<sol>l> regex
2656This construct cannot be used within the scope of
2744modifier), this construct assumes that the execution-time locale will be
2657C<use locale> (or the C<E<sol>l> regex modifier).
2745a UTF-8 one, and the generated pattern always uses Unicode rules. What
2746gets matched or not thus isn't dependent on the actual runtime locale, so
2747tainting is not enabled. But a C<locale> category warning is raised
2748if the runtime locale turns out to not be UTF-8.
27492658
27502659=end original
27512660
2752C<use locale> (または C<E<sol>l> 正規表現修飾子)の
2661この構文は、C<use locale> (または C<E<sol>l> 正規表現修飾子)の
2753スコープ内でコンパイルされると、この構文実行時ロケールが
2662スコープ内では使用できません。
2754UTF-8 のものであることを仮定し、
2755生成されたパターンは常に Unicode の規則を使います。
2756従ってマッチングするかどうかは実際の実行時ロケールには関係なく、
2757汚染チェックモードは有効になりません。
2758しかし、実行時ロケールが UTF-8 以外になると、
2759C<locale> カテゴリの警告が発生します。
27602663
27612664=item 2
27622665
27632666=begin original
27642667
27652668Any
27662669L<user-defined property|perlunicode/"User-Defined Character Properties">
27672670used must be already defined by the time the regular expression is
27682671compiled (but note that this construct can be used instead of such
27692672properties).
27702673
27712674=end original
27722675
27732676使用される
27742677L<ユーザー定義特性|perlunicode/"User-Defined Character Properties"> は、
27752678正規表現がコンパイルされるときにすでに定義されている必要があります
27762679(ただし、このような特性の代わりにこの構文を使用することもできます)。
27772680
27782681=item 3
27792682
27802683=begin original
27812684
27822685A regular expression that otherwise would compile
27832686using C<E<sol>d> rules, and which uses this construct will instead
27842687use C<E<sol>u>. Thus this construct tells Perl that you don't want
27852688C<E<sol>d> rules for the entire regular expression containing it.
27862689
27872690=end original
27882691
27892692C<E<sol>d> 規則を使用してコンパイルされ、この構文を使用する正規表現は、
27902693代わりに C<E<sol>u> を使用します。
27912694したがって、この構文は、C<E<sol>d> 規則が含まれている
27922695正規表現全体に対して C<E<sol>d> 規則が必要ないことを Perl に通知します。
27932696
27942697=back
27952698
27962699=begin original
27972700
27982701Note that skipping white space applies only to the interior of this
27992702construct. There must not be any space between any of the characters
28002703that form the initial C<(?[>. Nor may there be space between the
28012704closing C<])> characters.
28022705
28032706=end original
28042707
28052708空白のスキップは、この構造体の内部にのみ適用されることに注意してください。
28062709最初の C<(?[> を形成する文字の間に空白を入れることはできません。
28072710また、終わりの C<])> 文字の間に空白を入れることもできません。
28082711
28092712=begin original
28102713
28112714Just as in all regular expressions, the pattern can be built up by
28122715including variables that are interpolated at regex compilation time.
2813But currently each such sub-component should be an already-compiled
2716Care must be taken to ensure that you are getting what you expect. For
2814extended bracketed character class.
2717example:
28152718
28162719=end original
28172720
28182721すべての正規表現と同様に、正規表現コンパイル時に補完される変数を
28192722含めることでパターンを構築できます。
2820しかし、現在所、このような部分素のそれぞれは
2723期待どおり結果が得られるように注意が必です。
2821すでにコンパイルされた拡張大かっこ文字クラスであるべきです。
2724例えば:
28222725
2823 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2726 my $thai_or_lao = '\p{Thai} + \p{Lao}';
28242727 ...
28252728 qr/(?[ \p{Digit} & $thai_or_lao ])/;
28262729
28272730=begin original
28282731
2829If you interpolate something else, the pattern may still compile (or it
2732compiles to
2830may die), but if it compiles, it very well may not behave as you would
2831expect:
28322733
28332734=end original
28342735
2835何か違うものを変数展開すると、パターンやはりコンパイルされます
2736これ次のようにコンパイルされます:
2836(あるいは die します)が、コンパイルされると、想像しているものと
2837かなり違う振る舞いになるかもしれません:
28382737
2839 my $thai_or_lao = '\p{Thai} + \p{Lao}';
2738 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
2840 qr/(?[ \p{Digit} & $thai_or_lao ])/;
28412739
28422740=begin original
28432741
2844compiles to
2742But this does not have the effect that someone reading the code would
2743likely expect, as the intersection applies just to C<\p{Thai}>,
2744excluding the Laotian. Pitfalls like this can be avoided by
2745parenthesizing the component pieces:
28452746
28462747=end original
28472748
2848これは次のようにコンパイルされす:
2749しかし、これは、コードを読んでいる人が期待するような効果はありせん;
2750なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
2751適用されないからです。
2752このような落とし穴は、コンポーネントをかっこで囲むことで回避できます:
28492753
2850 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
2754 my $thai_or_lao = '( \p{Thai} + \p{Lao} )';
28512755
28522756=begin original
28532757
2854This does not have the effect that someone reading the source code
2758But any modifiers will still apply to all the components:
2855would likely expect, as the intersection applies just to C<\p{Thai}>,
2856excluding the Laotian.
28572759
28582760=end original
28592761
2860これはソースコードを読んでいる人が期待するような効果はありせん;
2762ただし修飾子はすべてのンポネントに適用されす:
2861なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
2862適用されないからです。
28632763
2764 my $lower = '\p{Lower} + \p{Digit}';
2765 qr/(?[ \p{Greek} & $lower ])/i;
2766
28642767=begin original
28652768
2769matches upper case things. You can avoid surprises by making the
2770components into instances of this construct by compiling them:
2771
2772=end original
2773
2774これは大文字のものと一致します。
2775コンポーネントをコンパイルしてこの構文の実体にすることで、
2776予期せぬ事態を避けることができます:
2777
2778 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2779 my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
2780
2781=begin original
2782
2783When these are embedded in another pattern, what they match does not
2784change, regardless of parenthesization or what modifiers are in effect
2785in that outer pattern.
2786
2787=end original
2788
2789これらが別のパターンに埋め込まれている場合、親子関係やその外側のパターンで
2790有効な修飾子に関係なく、一致するものは変わりません。
2791
2792=begin original
2793
28662794Due to the way that Perl parses things, your parentheses and brackets
28672795may need to be balanced, even including comments. If you run into any
2868examples, please submit them to L<https://github.com/Perl/perl5/issues>,
2796examples, please send them to C<perlbug@perl.org>, so that we can have a
2869so that we can have a concrete example for this man page.
2797concrete example for this man page.
28702798
28712799=end original
28722800
28732801Perl の構文解析方法によっては、コメントを含めてもかっこと大かっこの
28742802バランスを取る必要がある場合があります。
2875もし何か例を見つけたら、L<https://github.com/Perl/perl5/issues>
2803もし何か例を見つけたら、C<perlbug@perl.org> まで送ってください。
2876登録してください;
28772804そうすれば、この man ページの具体的な例を得ることができます。
2805
2806=begin original
2807
2808We may change it so that things that remain legal uses in normal bracketed
2809character classes might become illegal within this experimental
2810construct. One proposal, for example, is to forbid adjacent uses of the
2811same character, as in C<(?[ [aa] ])>. The motivation for such a change
2812is that this usage is likely a typo, as the second "a" adds nothing.
2813
2814=end original
2815
2816たとえば、C<(?[ [aa] ])> のように、同じ文字を隣接して使用すること
2817を禁止することが提案されています。
2818このような変更の動機は、2 番目の "a" は何も追加しないので、この使用は
2819タイプミスである可能性が高いということです。
28782820
28792821=begin meta
28802822
28812823Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1-)
28822824Status: completed
28832825
28842826=end meta