perlrecharclass > 5.10.1 との差分

perlrecharclass 5.10.1 と 5.40.0 の差分

11
2=encoding euc-jp
2=encoding utf8
33
44=head1 NAME
5X<character class>
56
67=begin original
78
89perlrecharclass - Perl Regular Expression Character Classes
910
1011=end original
1112
1213perlrecharclass - Perl 正規表現文字クラス
1314
1415=head1 DESCRIPTION
1516
1617=begin original
1718
1819The top level documentation about Perl regular expressions
1920is found in L<perlre>.
2021
2122=end original
2223
2324Perl 正規表現に関する最上位文書は L<perlre> です。
2425
2526=begin original
2627
2728This manual page discusses the syntax and use of character
28classes in Perl Regular Expressions.
29classes in Perl regular expressions.
2930
3031=end original
3132
3233このマニュアルページは Perl 正規表現の文字クラスの文法と使用法について
3334議論します。
3435
3536=begin original
3637
37A character class is a way of denoting a set of characters,
38A character class is a way of denoting a set of characters
3839in such a way that one character of the set is matched.
39It's important to remember that matching a character class
40It's important to remember that: matching a character class
4041consumes exactly one character in the source string. (The source
4142string is the string the regular expression is matched against.)
4243
4344=end original
4445
4546文字クラスは、集合の中の一文字がマッチングするというような方法で、
4647文字の集合を指定するための方法です。
47文字集合はソース文字列の中から正確に一文字だけを消費するということを
48次のことを覚えておくことは重要です: 文字集合はソース文字列の中から正確に
48覚えておくことは重要です。
49一文字だけを消費します。
4950(ソース文字列とは正規表現がマッチングしようとしている文字列です。)
5051
5152=begin original
5253
5354There are three types of character classes in Perl regular
54expressions: the dot, backslashed sequences, and the bracketed form.
55expressions: the dot, backslash sequences, and the form enclosed in square
56brackets. Keep in mind, though, that often the term "character class" is used
57to mean just the bracketed form. Certainly, most Perl documentation does that.
5558
5659=end original
5760
5861Perl 正規表現には 3 種類の文字クラスがあります: ドット、
59逆スラッシュシーケンス、かっこ付き形式です。
62逆スラッシュシーケンス、かっこで囲まれた形式です。
63しかし、「文字クラス」という用語はしばしば大かっこ形式だけを意味するために
64使われることに注意してください。
65確かに、ほとんどの Perl 文書ではそうなっています。
6066
6167=head2 The dot
6268
6369(ドット)
6470
6571=begin original
6672
6773The dot (or period), C<.> is probably the most used, and certainly
6874the most well-known character class. By default, a dot matches any
69character, except for the newline. The default can be changed to
75character, except for the newline. That default can be changed to
70add matching the newline with the I<single line> modifier: either
76add matching the newline by using the I<single line> modifier:
71for the entire regular expression using the C</s> modifier, or
77for the entire regular expression with the C</s> modifier, or
72locally using C<(?s)>.
78locally with C<(?s)> (and even globally within the scope of
79L<C<use re '/s'>|re/'E<sol>flags' mode>). (The C<L</\N>> backslash
80sequence, described
81below, matches any character except newline without regard to the
82I<single line> modifier.)
7383
7484=end original
7585
7686ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に
7787もっともよく知られている文字クラスです。
7888デフォルトでは、ドットは改行を除く任意の文字にマッチングします。
79デフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
89このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
8090変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには
81C<(?s)> を使います
91C<(?s)> を使います
92(そしてグローバルに L<C<use re '/s'>|re/'E<sol>flags' mode> の
93スコープ内の場合でもそうです)。
94(後述する C<L</\N>> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
95関わりなく改行以外の任意の文字にマッチングします。)
8296
8397=begin original
8498
8599Here are some examples:
86100
87101=end original
88102
89103以下は例です:
90104
91105=begin original
92106
93107 "a" =~ /./ # Match
94108 "." =~ /./ # Match
95109 "" =~ /./ # No match (dot has to match a character)
96110 "\n" =~ /./ # No match (dot does not match a newline)
97111 "\n" =~ /./s # Match (global 'single line' modifier)
98112 "\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
99113 "ab" =~ /^.$/ # No match (dot matches one character)
100114
101115=end original
102116
103117 "a" =~ /./ # マッチングする
104118 "." =~ /./ # マッチングする
105119 "" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
106120 "\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
107121 "\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
108122 "\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
109123 "ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
110124
111=head2 Backslashed sequences
125=head2 Backslash sequences
126X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
127X<\N> X<\v> X<\V> X<\h> X<\H>
128X<word> X<whitespace>
112129
113130(逆スラッシュシーケンス)
114131
115132=begin original
116133
117Perl regular expressions contain many backslashed sequences that
134A backslash sequence is a sequence of characters, the first one of which is a
118constitute a character class. That is, they will match a single
135backslash. Perl ascribes special meaning to many such sequences, and some of
119character, if that character belongs to a specific set of characters
136these are character classes. That is, they match a single character each,
120(defined by the sequence). A backslashed sequence is a sequence of
137provided that the character belongs to the specific set of characters defined
121characters starting with a backslash. Not all backslashed sequences
138by the sequence.
122are character class; for a full list, see L<perlrebackslash>.
123139
124140=end original
125141
126Perl 正規表現には、文字クラスを構成する多くの逆スラッシュシーケンス
142逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。
127ちます。
143Perl はそのような並びの多くに特別な意味をたせていて、
128これは(シーケンスで定義される)ある特定文字集合に属するつの文字
144の一部は文字クラスです。
129マッチングしす。
145り、それらはそれぞれ並びによって定義されている特定の文字の集合に
130逆スラシュシーケスは、逆スラッシュで始る並びです。
146帰属する一文字にマグします。
131全ての逆スラッシュシーケンスが文字クラスというわけではありません; 完全な
132リストは、L<perlrebackslash> を参照してください。
133147
134148=begin original
135149
136Here's a list of the backslashed sequences, which are discussed in
150Here's a list of the backslash sequences that are character classes. They
137more detail below.
151are discussed in more detail below. (For the backslash sequences that aren't
152character classes, see L<perlrebackslash>.)
138153
139154=end original
140155
141以下は逆スラッシュシーケンスの一覧です; 以下でさらに詳細に議論します。
156以下は文字クラスの逆スラッシュシーケンスの一覧です。
157以下でさらに詳細に議論します。
158(文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を
159参照してください。)
142160
143161=begin original
144162
145 \d Match a digit character.
163 \d Match a decimal digit character.
146 \D Match a non-digit character.
164 \D Match a non-decimal-digit character.
147165 \w Match a "word" character.
148166 \W Match a non-"word" character.
149 \s Match a white space character.
167 \s Match a whitespace character.
150 \S Match a non-white space character.
168 \S Match a non-whitespace character.
151 \h Match a horizontal white space character.
169 \h Match a horizontal whitespace character.
152 \H Match a character that isn't horizontal white space.
170 \H Match a character that isn't horizontal whitespace.
153 \v Match a vertical white space character.
171 \v Match a vertical whitespace character.
154 \V Match a character that isn't vertical white space.
172 \V Match a character that isn't vertical whitespace.
155 \pP, \p{Prop} Match a character matching a Unicode property.
173 \N Match a character that isn't a newline.
156 \PP, \P{Prop} Match a character that doesn't match a Unicode property.
174 \pP, \p{Prop} Match a character that has the given Unicode property.
175 \PP, \P{Prop} Match a character that doesn't have the Unicode property
157176
158177=end original
159178
160 \d 数字にマッチング。
179 \d 10 進数字にマッチング。
161 \D 非数字にマッチング。
180 \D 非 10 進数字にマッチング。
162181 \w 「単語」文字にマッチング。
163182 \W 非「単語」文字にマッチング。
164183 \s 空白文字にマッチング。
165184 \S 非空白文字にマッチング。
166185 \h 水平空白文字にマッチング。
167186 \H 水平空白でない文字にマッチング。
168187 \v 垂直空白文字にマッチング。
169188 \V 垂直空白でない文字にマッチング。
170 \pP, \p{Prop} Unicode 特性にマッチする文字にマッチング。
189 \N 改行以外の文字にマッチング。
171 \PP, \P{Prop} Unicode 特性にマッチしない文字にマッチング。
190 \pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
191 \PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
172192
193=head3 \N
194
195=begin original
196
197C<\N>, available starting in v5.12, like the dot, matches any
198character that is not a newline. The difference is that C<\N> is not influenced
199by the I<single line> regular expression modifier (see L</The dot> above). Note
200that the form C<\N{...}> may mean something completely different. When the
201C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
202character that many times. For example, C<\N{3}> means to match 3
203non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}>
204is not a legal quantifier, it is presumed to be a named character. See
205L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and
206C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
207names are respectively C<COLON>, C<4F>, and C<F4>.
208
209=end original
210
211v5.12 から利用可能な C<\N> は、ドットのように、
212改行以外の任意の文字にマッチングします。
213違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです
214(上述の L</The dot> 参照)。
215C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに
216注意してください。
217C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の
218非改行文字にマッチングします。
219例えば、C<\N{3}> は三つの非改行にマッチングします;
220C<\N{5,}> は五つ以上の非改行にマッチングします。
221しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と
222推定されます。
223これについては L<charnames> を参照してください。
224例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な
225量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の
226文字を探そうとします。
227
173228=head3 Digits
174229
175230(数字)
176231
177232=begin original
178233
179C<\d> matches a single character that is considered to be a I<digit>.
234C<\d> matches a single character considered to be a decimal I<digit>.
180What is considered a digit depends on the internal encoding of
235If the C</a> regular expression modifier is in effect, it matches [0-9].
181the source string. If the source string is in UTF-8 format, C<\d>
236Otherwise, it
182not only matches the digits '0' - '9', but also Arabic, Devanagari and
237matches anything that is matched by C<\p{Digit}>, which includes [0-9].
183digits from other languages. Otherwise, if there is a locale in effect,
238(An unlikely possible exception is that under locale matching rules, the
184it will match whatever characters the locale considers digits. Without
239current locale might not have C<[0-9]> matched by C<\d>, and/or might match
185a locale, C<\d> matches the digits '0' to '9'.
240other characters whose code point is less than 256. The only such locale
186See L</Locale, Unicode and UTF-8>.
241definitions that are legal would be to match C<[0-9]> plus another set of
24210 consecutive digit characters; anything else would be in violation of
243the C language standard, but Perl doesn't currently assume anything in
244regard to this.)
187245
188246=end original
189247
190C<\d> は I<数字> と考えられる単一の文字にマッチングします。
248C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。
191数字と考えらるかソース文字列の内部エコーディンに依存します。
249C</a> 正規表現修飾子有効の場合、これは [0-9] にマッチングします。
192ソース文字列が UTF-8 形式C<\d> 数字 '0' - '9' だけでなくArabic,
250さもければこれC<[0-9]> を含むC<\p{Digit}> にマッチングするものに
193Devanagari およびその他の言語の数字もマッチングします。
194さもなければ、ロケールが有効なら、ロケールが数字と考える文字に
195251マッチングします。
196ロケールがなければ、C<\d> は '0' から '9' の数字にマッチングします。
252(ありそうもない例外はロケールマッチングの下で、現在のロケールが
197L</Locale, Unicode and UTF-8> を参照してくださ
253C<\d> にマッチングする [0-9] がなか、
254符号位置が 256 未満の他の文字にマッチングすることです。
255唯一正当なロケール定義は、C<[0-9]> に加えてもう一つの 10 の連続した
256数字の集合にマッチングするもので、
257それ以外は C 言語標準に違反していますが、
258Perl は今のところこれに関して何も仮定しません。)
198259
199260=begin original
200261
201Any character that isn't matched by C<\d> will be matched by C<\D>.
262What this means is that unless the C</a> modifier is in effect C<\d> not
263only matches the digits '0' - '9', but also Arabic, Devanagari, and
264digits from other languages. This may cause some confusion, and some
265security issues.
202266
203267=end original
204268
269これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字
270'0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の
271数字もマッチングします。
272これは混乱やセキュリティ問題を引き起こすことがあります。
273
274=begin original
275
276Some digits that C<\d> matches look like some of the [0-9] ones, but
277have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks
278very much like an ASCII DIGIT EIGHT (U+0038), and LEPCHA DIGIT SIX
279(U+1C46) looks very much like an ASCII DIGIT FIVE (U+0035). An
280application that
281is expecting only the ASCII digits might be misled, or if the match is
282C<\d+>, the matched string might contain a mixture of digits from
283different writing systems that look like they signify a number different
284than they actually do. L<Unicode::UCD/num()> can
285be used to safely
286calculate the value, returning C<undef> if the input string contains
287such a mixture. Otherwise, for example, a displayed price might be
288deliberately different than it appears.
289
290=end original
291
292C<\d> にマッチングする数字には、[0-9] のように見えるけれども、
293異なる値を持つものもあります。
294例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038) に
295とてもよく似ていて、
296LEPCHA DIGIT SIX (U+1C46) は ASCII DIGIT FIVE (U+0035) に
297とてもよく似ています。
298ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、
299マッチングが C<\d+> の場合、
300マッチングした文字列は、実際と異なる値を示しているように見える、
301異なった書記体系からの数字が混ざったものかもしれません。
302L<Unicode::UCD/num()> は値を安全に計算するのに使えます;
303入力文字列がこのような混合を含んでいる場合は C<undef> を返します。
304さもなければ、例えば、表示された価格は見た目と意図的に違うものに
305なるかもしれません。
306
307=begin original
308
309What C<\p{Digit}> means (and hence C<\d> except under the C</a>
310modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
311C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this
312is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
313But Unicode also has a different property with a similar name,
314C<\p{Numeric_Type=Digit}>, which matches a completely different set of
315characters. These characters are things such as C<CIRCLED DIGIT ONE>
316or subscripts, or are from writing systems that lack all ten digits.
317
318=end original
319
320C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、
321C<\p{General_Category=Decimal_Number}>、または同義語として
322C<\p{General_Category=Digit}> です。
323Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に
324マッチングする文字集合と同じです。
325ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ
326別の特性もあります; これは完全に異なる文字集合とマッチングします。
327これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、
32810 の数字すべてが揃っていない書記体系からのものです。
329
330=begin original
331
332The design intent is for C<\d> to exactly match the set of characters
333that can safely be used with "normal" big-endian positional decimal
334syntax, where, for example 123 means one 'hundred', plus two 'tens',
335plus three 'ones'. This positional notation does not necessarily apply
336to characters that match the other type of "digit",
337C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
338
339=end original
340
341設計意図は、C<\d> が「通常の」ビッグエンディアンの
342位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を
343加えたものを意味する) で安全に使用できる文字集合と
344正確にマッチングするようにすることです。
345この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に
346マッチングする文字には必ずしも適用されないため、
347C<\d> はこれらの文字にマッチングしません。
348
349=begin original
350
351The Tamil digits (U+0BE6 - U+0BEF) can also legally be
352used in old-style Tamil numbers in which they would appear no more than
353one in a row, separated by characters that mean "times 10", "times 100",
354etc. (See L<https://www.unicode.org/notes/tn21>.)
355
356=end original
357
358タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の
359数字でも合法的に使用することができます;
360この数字は、「×10」や「×100」などを意味する文字で区切られて、
3611 回に一度にしか現れません。
362(L<https://www.unicode.org/notes/tn21>を参照してください。)
363
364=begin original
365
366Any character not matched by C<\d> is matched by C<\D>.
367
368=end original
369
205370C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。
206371
207372=head3 Word characters
208373
209374(単語文字)
210375
211376=begin original
212377
213C<\w> matches a single I<word> character: an alphanumeric character
378A C<\w> matches a single alphanumeric character (an alphabetic character, or a
214(that is, an alphabetic character, or a digit), or the underscore (C<_>).
379decimal digit); or a connecting punctuation character, such as an
215What is considered a word character depends on the internal encoding
380underscore ("_"); or a "mark" character (like some sort of accent) that
216of the string. If it's in UTF-8 format, C<\w> matches those characters
381attaches to one of those. It does not match a whole word. To match a
217that are considered word characters in the Unicode database. That is, it
382whole word, use C<\w+>. This isn't the same thing as matching an
218not only matches ASCII letters, but also Thai letters, Greek letters, etc.
383English word, but in the ASCII range it is the same as a string of
219If the source string isn't in UTF-8 format, C<\w> matches those characters
384Perl-identifier characters.
220that are considered word characters by the current locale. Without
221a locale in effect, C<\w> matches the ASCII letters, digits and the
222underscore.
223385
224386=end original
225387
226C<\w> は単一の I<単> 文字にマッチングします: これは英数字(つまり英字または
388C<\w> は単語全体でなく、単一の英数字(つまり英字または数字)または
227数字)および下線 (C<_>) です。
389下線(C<_>) のような接続句読点
228何が単語文字と考えられるかは文字列内部エディング依存します。
390またはこらの一つに付いてい(ある種アクセトのような)「マク」文字
229UTF-8 形式の場合、C<\w> は Unicode データベースで単語文字と考えられるものに
230391マッチングします。
231これは、ASCII の文字だけではなく、タイの文字、ギリシャの文字、など
392これは単語全体はマッチングしません。
232マッチングするうことです
393単語全体にマッチングするには、C<\w+> を使ってください。
233ソース文字列が UTF-8 形式でない場合、C<\w> 現在ロケールで単語文字
394これ英語の単語にマッチングするの同じことではありませんが、
234考えられるもにマッチングします。
395ASCII 範囲では、Perl の識別子文字の文字列と同じです。
235ロケールが有効でない場合、C<\w> は ASCII 文字、数字、下線に
397=over
398
399=item If the C</a> modifier is in effect ...
400
401(C</a> 修飾子が有効なら ...)
402
403=begin original
404
405C<\w> matches the 63 characters [a-zA-Z0-9_].
406
407=end original
408
409C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。
410
411=item otherwise ...
412
413(さもなければ ...)
414
415=over
416
417=item For code points above 255 ...
418
419(256 以上の符号位置では ...)
420
421=begin original
422
423C<\w> matches the same as C<\p{Word}> matches in this range. That is,
424it matches Thai letters, Greek letters, etc. This includes connector
425punctuation (like the underscore) which connect two words together, or
426diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
427are generally used to add auxiliary markings to letters.
428
429=end original
430
431C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに
236432マッチングします。
433つまり、タイ文字、ギリシャ文字などです。
434これには(下線のような)二つの単語を繋ぐ接続句読点、
435C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために
436使われる修飾字のようなダイアクリティカルマークが含まれます。
237437
438=item For code points below 256 ...
439
440(255 以下の符号位置では ...)
441
442=over
443
444=item if locale rules are in effect ...
445
446(ロケール規則が有効なら ...)
447
238448=begin original
239449
240Any character that isn't matched by C<\w> will be matched by C<\W>.
450C<\w> matches the platform's native underscore character plus whatever
451the locale considers to be alphanumeric.
241452
242453=end original
243454
455C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と
456考えるものにマッチングします。
457
458=item if, instead, Unicode rules are in effect ...
459
460(そうではなく、Unicode 規則が有効なら ...)
461
462=begin original
463
464C<\w> matches exactly what C<\p{Word}> matches.
465
466=end original
467
468C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。
469
470=item otherwise ...
471
472(さもなければ ...)
473
474=begin original
475
476C<\w> matches [a-zA-Z0-9_].
477
478=end original
479
480C<\w> は [a-zA-Z0-9_] にマッチングします。
481
482=back
483
484=back
485
486=back
487
488=begin original
489
490Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
491
492=end original
493
494どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
495記述されている方法で決定されます。
496
497=begin original
498
499There are a number of security issues with the full Unicode list of word
500characters. See L<https://unicode.org/reports/tr36>.
501
502=end original
503
504完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。
505L<https://unicode.org/reports/tr36> を参照してください。
506
507=begin original
508
509Also, for a somewhat finer-grained set of characters that are in programming
510language identifiers beyond the ASCII range, you may wish to instead use the
511more customized L</Unicode Properties>, C<\p{ID_Start}>,
512C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See
513L<http://unicode.org/reports/tr31>.
514
515=end original
516
517また、ASCII の範囲を超えたプログラミング言語識別子のための
518より高精度の文字集合のためには、代わりによりカスタマイズされた
519L<Unicode 特性|/Unicode Properties>である
520 C<\p{ID_Start}>,
521C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を
522使った方がよいでしょう。
523L<http://unicode.org/reports/tr31> を参照してください。
524
525=begin original
526
527Any character not matched by C<\w> is matched by C<\W>.
528
529=end original
530
244531C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。
245532
246=head3 White space
533=head3 Whitespace
247534
248535(空白)
249536
250537=begin original
251538
252C<\s> matches any single character that is consider white space. In the
539C<\s> matches any single character considered whitespace.
253ASCII range, C<\s> matches the horizontal tab (C<\t>), the new line
254(C<\n>), the form feed (C<\f>), the carriage return (C<\r>), and the
255space (the vertical tab, C<\cK> is not matched by C<\s>). The exact set
256of characters matched by C<\s> depends on whether the source string is
257in UTF-8 format. If it is, C<\s> matches what is considered white space
258in the Unicode database. Otherwise, if there is a locale in effect, C<\s>
259matches whatever is considered white space by the current locale. Without
260a locale, C<\s> matches the five characters mentioned in the beginning
261of this paragraph. Perhaps the most notable difference is that C<\s>
262matches a non-breaking space only if the non-breaking space is in a
263UTF-8 encoded string.
264540
265541=end original
266542
267543C<\s> は空白と考えられる単一の文字にマッチングします。
268ASCII の範囲では、C<\s> は水平タブ(C<\t>)、改行(C<\n>)、ページ送り(C<\f>)、
269復帰(C<\r>)、スペースにマッチングします (垂直タブ C<\cK> は C<\s> に
270マッチングしません)。
271C<\s> がマッチングする文字の正確な集合はソース文字列が UTF-8 形式かどうかに
272依存します。
273もしそうなら、C<\s> は Unicode データベースで空白と考えられるものに
274マッチングします。
275さもなければ、ロケールが有効なら、C<\s> は現在のロケールで空白と
276考えられるものにマッチングします。
277ロケールなしでは、C<\s> はこの段落の始めに言及した五つの文字に
278マッチングします。
279おそらくもっとも顕著な違いは、non-breaking space は UTF-8 エンコードされた
280文字列にある場合にのみ、C<\s> にマッチングするということです。
281544
545=over
546
547=item If the C</a> modifier is in effect ...
548
549(C</a> 修飾子が有効なら ...)
550
282551=begin original
283552
284Any character that isn't matched by C<\s> will be matched by C<\S>.
553In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that
554is, the horizontal tab,
555the newline, the form feed, the carriage return, and the space.
556Starting in Perl v5.18, it also matches the vertical tab, C<\cK>.
557See note C<[1]> below for a discussion of this.
285558
286559=end original
287560
288C<\s> にマッチングしない任意の文字C<\S> にマッチングします
561全ての Perl バージョンで、C<\s> は [\t\n\f\r ] の 5 文字にマッチングします;
562つまり、水平タブ、改行、改頁、復帰、スペースです。
563Perl 5.18 から、垂直タブ C<\cK> にもマッチングします。
564ここでの議論については後述する C<[1]> を参照してください。
289565
566=item otherwise ...
567
568(さもなければ ...)
569
570=over
571
572=item For code points above 255 ...
573
574(256 以上の符号位置では ...)
575
290576=begin original
291577
292C<\h> will match any character that is considered horizontal white space;
578C<\s> matches exactly the code points above 255 shown with an "s" column
293this includes the space and the tab characters. C<\H> will match any character
579in the table below.
294that is not considered horizontal white space.
295580
296581=end original
297582
298C<\h> は水平空白と考えられ任意文字にマッチングします; はスペースと
583C<\s> は、後述す"s" の列で示さている、
299タブ文字です。
584255 を超える符号位置に正確にマッチングします。
300C<\H> は水平空白と考えられない文字にマッチングします。
301585
586=item For code points below 256 ...
587
588(255 以下の符号位置では ...)
589
590=over
591
592=item if locale rules are in effect ...
593
594(ロケール規則が有効なら ...)
595
302596=begin original
303597
304C<\v> will match any character that is considered vertical white space;
598C<\s> matches whatever the locale considers to be whitespace.
305this includes the carriage return and line feed characters (newline).
306C<\V> will match any character that is not considered vertical white space.
307599
308600=end original
309601
310C<\v> は垂直空白と考えられ任意文字にマッチングします; これは復帰と
602C<\s> はロケールが空白と考えるのにマッチングします
311行送り(改行)文字です。
312C<\V> は垂直空白と考えられない任意の文字にマッチングします。
313603
604=item if, instead, Unicode rules are in effect ...
605
606(そうではなく、Unicode 規則が有効なら ...)
607
314608=begin original
315609
316C<\R> matches anything that can be considered a newline under Unicode
610C<\s> matches exactly the characters shown with an "s" column in the
317rules. It's not a character class, as it can match a multi-character
611table below.
318sequence. Therefore, it cannot be used inside a bracketed character
319class. Details are discussed in L<perlrebackslash>.
320612
321613=end original
322614
323C<\R> は Unicode規則で改行と考えられものにマッチングします。
615C<\s> は正確に以下の表で "s"列にあ文字にマッチングします。
324複数文字の並びにマッチングすることもあるので、これは
325文字クラスではありません。
326従って、大かっこ文字クラスの中では使えません。
327詳細は L<perlrebackslash> で議論しています。
328616
617=item otherwise ...
618
619(さもなければ ...)
620
329621=begin original
330622
331C<\h>, C<\H>, C<\v>, C<\V>, and C<\R> are new in perl 5.10.0.
623C<\s> matches [\t\n\f\r ] and, starting in Perl
624v5.18, the vertical tab, C<\cK>.
625(See note C<[1]> below for a discussion of this.)
626Note that this list doesn't include the non-breaking space.
332627
333628=end original
334629
335C<\h>, C<\H>, C<\v>, C<\V>, C<\R> perl 5.10.0 の新機能です。
630C<\s> [\t\n\f\r ] にマッチングし、Perl v5.18 から、
631垂直タブ C<\cK> にもマッチングします。
632(これの議論については後述する C<[1]> を参照してください。)
633この一覧にはノーブレークスペースが含まれていないことに注意してください。
336634
635=back
636
637=back
638
639=back
640
337641=begin original
338642
339Note that unlike C<\s>, C<\d> and C<\w>, C<\h> and C<\v> always match
643Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
340the same characters, regardless whether the source string is in UTF-8
341format or not. The set of characters they match is also not influenced
342by locale.
343644
344645=end original
345646
346C<\s>, C<\d>, C<\w> と違って、C<\h> および C<\v> はソース文字列が
647どの規則を適用するかは L<perlre/Which character set modifier is in effect?>
347UTF-8 形式かどうかに関わらず同じ文字にマッチングします。
648記述されている方法で決定されます。
348マッチングする文字の集合はロケールの影響も受けません。
349649
350650=begin original
351651
352One might think that C<\s> is equivalent with C<[\h\v]>. This is not true.
652Any character not matched by C<\s> is matched by C<\S>.
353The vertical tab (C<"\x0b">) is not matched by C<\s>, it is however
354considered vertical white space. Furthermore, if the source string is
355not in UTF-8 format, the next line (C<"\x85">) and the no-break space
356(C<"\xA0">) are not matched by C<\s>, but are by C<\v> and C<\h> respectively.
357If the source string is in UTF-8 format, both the next line and the
358no-break space are matched by C<\s>.
359653
360654=end original
361655
656C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。
657
658=begin original
659
660C<\h> matches any character considered horizontal whitespace;
661this includes the platform's space and tab characters and several others
662listed in the table below. C<\H> matches any character
663not considered horizontal whitespace. They use the platform's native
664character set, and do not consider any locale that may otherwise be in
665use.
666
667=end original
668
669C<\h> は水平空白と考えられる任意の文字にマッチングします; これは
670プラットフォームのスペースとタブ文字および以下の表に上げられている
671いくつかのその他の文字です。
672C<\H> は水平空白と考えられない文字にマッチングします。
673これらはプラットフォームのネイティブな文字集合を使い、
674他の場所では有効なロケールを考慮しません。
675
676=begin original
677
678C<\v> matches any character considered vertical whitespace;
679this includes the platform's carriage return and line feed characters (newline)
680plus several other characters, all listed in the table below.
681C<\V> matches any character not considered vertical whitespace.
682They use the platform's native character set, and do not consider any
683locale that may otherwise be in use.
684
685=end original
686
687C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは
688プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です;
689全ては以下の表に挙げられています。
690C<\V> は垂直空白と考えられない任意の文字にマッチングします。
691これらはプラットフォームのネイティブな文字集合を使い、
692他の場所では有効なロケールを考慮しません。
693
694=begin original
695
696C<\R> matches anything that can be considered a newline under Unicode
697rules. It can match a multi-character sequence. It cannot be used inside
698a bracketed character class; use C<\v> instead (vertical whitespace).
699It uses the platform's
700native character set, and does not consider any locale that may
701otherwise be in use.
702Details are discussed in L<perlrebackslash>.
703
704=end original
705
706C<\R> は Unicode の規則で改行と考えられるものにマッチングします。
707複数文字の並びにマッチングすることもあります。
708従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を
709使ってください。
710これらはプラットフォームのネイティブな文字集合を使い、
711他の場所では有効なロケールを考慮しません。
712詳細は L<perlrebackslash> で議論しています。
713
714=begin original
715
716Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
717the same characters, without regard to other factors, such as the active
718locale or whether the source string is in UTF-8 format.
719
720=end original
721
722C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の
723ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず
724同じ文字にマッチングします。
725
726=begin original
727
728One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true
729starting in Perl v5.18, but prior to that, the sole difference was that the
730vertical tab (C<"\cK">) was not matched by C<\s>.
731
732=end original
733
362734C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。
363これは正しくあません。
735Perl 5.18 からもちろん正しいです; しかしそれよ前では、
364垂直タブ (C<"\x0b">) は C<\s> にマッチングしませんが、垂直空白
736唯一の違いは、垂直タブ (C<"\xcK">) は C<\s> にマッチングしないいうことです。
365考えられます。
366さらに、ソース文字列が UTF-8 形式でなければ、next line (C<"\x85">) と
367no-break space (C<"\xA0">) は C<\s> にマッチングしませんが、
368それぞれ C<\v> および C<\h> にはマッチングします。
369ソース文字列が UTF-8 形式なら、next line と no-break space は C<\s> に
370マッチングします。
371737
372738=begin original
373739
374740The following table is a complete listing of characters matched by
375C<\s>, C<\h> and C<\v>.
741C<\s>, C<\h> and C<\v> as of Unicode 14.0.
376742
377743=end original
378744
379以下の表は C<\s>, C<\h>, C<\v> にマッチングする文字の完全な一覧です。
745以下の表は Unicode 14.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
746完全な一覧です。
380747
381748=begin original
382749
383The first column gives the code point of the character (in hex format),
750The first column gives the Unicode code point of the character (in hex format),
384751the second column gives the (Unicode) name. The third column indicates
385by which class(es) the character is matched.
752by which class(es) the character is matched (assuming no locale is in
753effect that changes the C<\s> matching).
386754
387755=end original
388756
389最初の列は文字の符号位置(16 進形式)、2 番目の列は (Unicode の)名前です。
757最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の)
3903 番目の列はどのクラスにマッチングするかを示しています。
758名前です。
7593 番目の列はどのクラスにマッチングするかを示しています
760(C<\s> のマッチングを変更するようなロケールが
761有効でないことを仮定しています)。
391762
392 0x00009 CHARACTER TABULATION h s
763 0x0009 CHARACTER TABULATION h s
393 0x0000a LINE FEED (LF) vs
764 0x000a LINE FEED (LF) vs
394 0x0000b LINE TABULATION v
765 0x000b LINE TABULATION vs [1]
395 0x0000c FORM FEED (FF) vs
766 0x000c FORM FEED (FF) vs
396 0x0000d CARRIAGE RETURN (CR) vs
767 0x000d CARRIAGE RETURN (CR) vs
397 0x00020 SPACE h s
768 0x0020 SPACE h s
398 0x00085 NEXT LINE (NEL) vs [1]
769 0x0085 NEXT LINE (NEL) vs [2]
399 0x000a0 NO-BREAK SPACE h s [1]
770 0x00a0 NO-BREAK SPACE h s [2]
400 0x01680 OGHAM SPACE MARK h s
771 0x1680 OGHAM SPACE MARK h s
401 0x0180e MONGOLIAN VOWEL SEPARATOR h s
772 0x2000 EN QUAD h s
402 0x02000 EN QUAD h s
773 0x2001 EM QUAD h s
403 0x02001 EM QUAD h s
774 0x2002 EN SPACE h s
404 0x02002 EN SPACE h s
775 0x2003 EM SPACE h s
405 0x02003 EM SPACE h s
776 0x2004 THREE-PER-EM SPACE h s
406 0x02004 THREE-PER-EM SPACE h s
777 0x2005 FOUR-PER-EM SPACE h s
407 0x02005 FOUR-PER-EM SPACE h s
778 0x2006 SIX-PER-EM SPACE h s
408 0x02006 SIX-PER-EM SPACE h s
779 0x2007 FIGURE SPACE h s
409 0x02007 FIGURE SPACE h s
780 0x2008 PUNCTUATION SPACE h s
410 0x02008 PUNCTUATION SPACE h s
781 0x2009 THIN SPACE h s
411 0x02009 THIN SPACE h s
782 0x200a HAIR SPACE h s
412 0x0200a HAIR SPACE h s
783 0x2028 LINE SEPARATOR vs
413 0x02028 LINE SEPARATOR vs
784 0x2029 PARAGRAPH SEPARATOR vs
414 0x02029 PARAGRAPH SEPARATOR vs
785 0x202f NARROW NO-BREAK SPACE h s
415 0x0202f NARROW NO-BREAK SPACE h s
786 0x205f MEDIUM MATHEMATICAL SPACE h s
416 0x0205f MEDIUM MATHEMATICAL SPACE h s
787 0x3000 IDEOGRAPHIC SPACE h s
417 0x03000 IDEOGRAPHIC SPACE h s
418788
419789=over 4
420790
421791=item [1]
422792
423793=begin original
424794
425NEXT LINE and NO-BREAK SPACE only match C<\s> if the source string is in
795Prior to Perl v5.18, C<\s> did not match the vertical tab.
426UTF-8 format.
796C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did.
427797
428798=end original
429799
430NEXT LINE と NO-BREAK SPACEソース文字列が UTF-8 形式の時のみ
800Perl v5.18 より前では、C<\s>垂直タブマッチングしませんでした。
431C<\s> にマッチングします。
801C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的
802マッチングしていたものにマッチングします。
432803
433=back
804=item [2]
434805
435806=begin original
436807
437It is worth noting that C<\d>, C<\w>, etc, match single characters, not
808NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
438complete numbers or words. To match a number (that consists of integers),
809on the rules in effect. See
439use C<\d+>; to match a word, use C<\w+>.
810L<the beginning of this section|/Whitespace>.
440811
441812=end original
442813
443C<\d>, C<\w> などは単語や数値全体ではなく単一の文字マッチングすると
814NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に
444いうことは注意する価値があります。
815マッチングしたマッチングしなかったりします。
445(整数で構成される)数値にマッチングするには、C<\d+> を使ってください; 単語に
816L<the beginning of this section|/Whitespace> を参照してください
446マッチングするには、C<\w+> を使ってください。
447817
818=back
819
448820=head3 Unicode Properties
449821
450822(Unicode 特性)
451823
452824=begin original
453825
454C<\pP> and C<\p{Prop}> are character classes to match characters that
826C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
455fit given Unicode classes. One letter classes can be used in the C<\pP>
827Unicode properties. One letter property names can be used in the C<\pP> form,
456form, with the class name following the C<\p>, otherwise, the property
828with the property name following the C<\p>, otherwise, braces are required.
457name is enclosed in braces, and follows the C<\p>. For instance, a
829When using braces, there is a single form, which is just the property name
458match for a number can be written as C</\pN/> or as C</\p{Number}/>.
830enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
459Lowercase letters are matched by the property I<LowercaseLetter> which
831which means to match if the property "name" for the character has that particular
460has as short form I<Ll>. They have to be written as C</\p{Ll}/> or
832"value".
461C</\p{LowercaseLetter}/>. C</\pLl/> is valid, but means something different.
833For instance, a match for a number can be written as C</\pN/> or as
834C</\p{Number}/>, or as C</\p{Number=True}/>.
835Lowercase letters are matched by the property I<Lowercase_Letter> which
836has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
837C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
838(the underscores are optional).
839C</\pLl/> is valid, but means something different.
462840It matches a two character string: a letter (Unicode property C<\pL>),
463841followed by a lowercase C<l>.
464842
465843=end original
466844
467C<\pP> と C<\p{Prop}> は指定された Unicode クラスに一致する文字に
845C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に
468846マッチングする文字クラスです。
469一文字クラスは C<\pP> 形式で、C<\p> に引き続いてクラス名です; さもなければ
847一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ
470特性名は中かっこで囲まれて、C<\p> に引き続きます。
848中かっこが必要です。
471例えば数字マッチングするものは C</\pN/> または C</\p{Number}/>
849中かっこを使うとき特性名を中かっこで囲んだ単一形式
472書けます。
850C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を
851持つものにマッチングすることになる複合形式があります。
852例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または
853C</\p{Number=True}/> と書けます。
473854小文字は I<LowercaseLetter> 特性にマッチングします; これには
474855I<Ll> と言う短縮形式があります。
475C</\p{Ll}/> または C</\p{LowercaseLetter}/> と書く必要がありす。
856中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または
857C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。
476858C</\pLl/> も妥当ですが、違う意味になります。
477859これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて
478860小文字の C<l> です。
479861
480862=begin original
481863
482For a list of possible properties, see
864What a Unicode property matches is never subject to locale rules, and
483L<perlunicode/Unicode Character Properties>. It is also possible to
865if locale rules are not otherwise in effect, the use of a Unicode
484defined your own properties. This is discussed in
866property will force the regular expression into using Unicode rules, if
867it isn't already.
868
869=end original
870
871Unicode 特性が何にマッチングするかは決してロケールの規則に影響されず、
872ロケール規則が有効でない場合、Unicode 特性を使うと
873正規表現に (まだそうでなければ) Unicode 規則を使うように強制します。
874
875=begin original
876
877Note that almost all properties are immune to case-insensitive matching.
878That 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
880C<Uppercase_Letter>,
881C<Lowercase_Letter>,
882and C<Titlecase_Letter>,
883all of which match C<Cased_Letter> under C</i> matching.
884The second set is
885C<Uppercase>,
886C<Lowercase>,
887and C<Titlecase>,
888all of which match C<Cased> under C</i> matching.
889(The difference between these sets is that some things, such as Roman
890numerals, come in both upper and lower case, so they are C<Cased>, but
891aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
892actually C<Letter_Number>s.)
893This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
894of which under C</i> match C<PosixAlpha>.
895
896=end original
897
898ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに
899注意してください。
900つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を
901与えないということです。
902しかし、影響を与える二つの集合があります。
903一つ目の集合は
904C<Uppercase_Letter>,
905C<Lowercase_Letter>,
906C<Titlecase_Letter> で、全て C</i> マッチングの下で
907C<Cased_Letter> にマッチングします。
908二つ目の集合は
909C<Uppercase>,
910C<Lowercase>,
911C<Titlecase> で、全てC</i> マッチングの下で
912C<Cased> にマッチングします。
913(これらの集合の違いは、ローマ数字のような一部のものは、
914大文字と小文字があるので C<Cased> ですが、
915文字とは扱われないので C<Cased_Letter> ではありません。
916これらは実際には C<Letter_Number> です。)
917この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます;
918これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。
919
920=begin original
921
922For more details on Unicode properties, see L<perlunicode/Unicode
923Character Properties>; for a
924complete list of possible properties, see
925L<perluniprops/Properties accessible through \p{} and \P{}>,
926which notes all forms that have C</i> differences.
927It is also possible to define your own properties. This is discussed in
485928L<perlunicode/User-Defined Character Properties>.
486929
487930=end original
488931
489特性のリストについては、L<perlunicode/Unicode Character Properties> を
932Unicode 特性に関するさらなる詳細については、
490参照してください
933L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な
934一覧については、C</i> に違いのある全ての形式について記されている
935L<perluniprops/Properties accessible through \p{} and \P{}> を参照して
936ください。
491937独自の特性を定義することも可能です。
492これは L<perlunicode/User-Defined Character Properties> で議論されています。
938これは L<perlunicode/User-Defined Character Properties> で
939議論されています。
493940
941=begin original
942
943Unicode properties are defined (surprise!) only on Unicode code points.
944Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats
945non-Unicode code points (those above the legal Unicode maximum of
9460x10FFFF) as if they were typical unassigned Unicode code points.
947
948=end original
949
950Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ
951定義されています。
952v5.20 から、C<\p> と C<\P> に対してマッチングするとき、
953Perl は
954非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) を、
955典型的な未割り当て Unicode 符号位置であるかのように扱います。
956
957=begin original
958
959Prior to v5.20, Perl raised a warning and made all matches fail on
960non-Unicode code points. This could be somewhat surprising:
961
962=end original
963
964v5.20 より前では、非 Unicode 符号位置に対しては全てのマッチングは失敗して、
965Perl は警告を出していました。
966これは驚かされるものだったかもしれません。
967
968 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails on Perls < v5.20.
969 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails on Perls
970 # < v5.20
971
972=begin original
973
974Even though these two matches might be thought of as complements, until
975v5.20 they were so only on Unicode code points.
976
977=end original
978
979これら二つのマッチングは補集合と考えるかもしれませんが、
980v5.20 まで、これらは Unicode 符号位置だけでした。
981
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
494992=head4 Examples
495993
496994(例)
497995
498996=begin original
499997
500998 "a" =~ /\w/ # Match, "a" is a 'word' character.
501999 "7" =~ /\w/ # Match, "7" is a 'word' character as well.
5021000 "a" =~ /\d/ # No match, "a" isn't a digit.
5031001 "7" =~ /\d/ # Match, "7" is a digit.
504 " " =~ /\s/ # Match, a space is white space.
1002 " " =~ /\s/ # Match, a space is whitespace.
5051003 "a" =~ /\D/ # Match, "a" is a non-digit.
5061004 "7" =~ /\D/ # No match, "7" is not a non-digit.
507 " " =~ /\S/ # No match, a space is not non-white space.
1005 " " =~ /\S/ # No match, a space is not non-whitespace.
5081006
5091007=end original
5101008
5111009 "a" =~ /\w/ # マッチング; "a" は「単語」文字。
5121010 "7" =~ /\w/ # マッチング; "7" も「単語」文字。
5131011 "a" =~ /\d/ # マッチングしない; "a" は数字ではない。
5141012 "7" =~ /\d/ # マッチング; "7" は数字。
5151013 " " =~ /\s/ # マッチング; スペースは空白。
5161014 "a" =~ /\D/ # マッチング; "a" は非数字。
5171015 "7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
5181016 " " =~ /\S/ # マッチングしない; スペースは非空白ではない。
5191017
5201018=begin original
5211019
522 " " =~ /\h/ # Match, space is horizontal white space.
1020 " " =~ /\h/ # Match, space is horizontal whitespace.
523 " " =~ /\v/ # No match, space is not vertical white space.
1021 " " =~ /\v/ # No match, space is not vertical whitespace.
524 "\r" =~ /\v/ # Match, a return is vertical white space.
1022 "\r" =~ /\v/ # Match, a return is vertical whitespace.
5251023
5261024=end original
5271025
5281026 " " =~ /\h/ # マッチング; スペースは水平空白。
5291027 " " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
5301028 "\r" =~ /\v/ # マッチング; 復帰は垂直空白。
5311029
5321030=begin original
5331031
5341032 "a" =~ /\pL/ # Match, "a" is a letter.
5351033 "a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.
5361034
5371035=end original
5381036
5391037 "a" =~ /\pL/ # マッチング; "a" は英字。
5401038 "a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。
5411039
5421040=begin original
5431041
5441042 "\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character
5451043 # 'THAI CHARACTER SO SO', and that's in
5461044 # Thai Unicode class.
547 "a" =~ /\P{Lao}/ # Match, as "a" is not a Laoian character.
1045 "a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character.
5481046
5491047=end original
5501048
5511049 "\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字
5521050 # 'THAI CHARACTER SO SO' で、これは
5531051 # Thai Unicode クラスにある。
5541052 "a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。
5551053
1054=begin original
1055
1056It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
1057complete numbers or words. To match a number (that consists of digits),
1058use C<\d+>; to match a word, use C<\w+>. But be aware of the security
1059considerations in doing so, as mentioned above.
1060
1061=end original
1062
1063C<\d>, C<\w> などは数値や単語全体ではなく、1 文字にマッチングすることは
1064強調する価値があります。
1065(数字で構成される) 数値 にマッチングするには C<\d+> を使います;
1066単語にマッチングするには C<\w+> を使います。
1067しかし前述したように、そうする場合のセキュリティ問題について
1068注意してください。
1069
5561070=head2 Bracketed Character Classes
5571071
5581072(かっこ付き文字クラス)
5591073
5601074=begin original
5611075
5621076The third form of character class you can use in Perl regular expressions
563is the bracketed form. In its simplest form, it lists the characters
1077is the bracketed character class. In its simplest form, it lists the characters
564that may be matched inside square brackets, like this: C<[aeiou]>.
1078that may be matched, surrounded by square brackets, like this: C<[aeiou]>.
565This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Just as the other
1079This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Like the other
566character classes, exactly one character will be matched. To match
1080character classes, exactly one character is matched.* To match
567a longer string consisting of characters mentioned in the characters
1081a longer string consisting of characters mentioned in the character
568class, follow the character class with a quantifier. For instance,
1082class, follow the character class with a L<quantifier|perlre/Quantifiers>. For
569C<[aeiou]+> matches a string of one or more lowercase ASCII vowels.
1083instance, C<[aeiou]+> matches one or more lowercase English vowels.
5701084
5711085=end original
5721086
573Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ形式です。
1087Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ文字クラスです。
5741088もっとも単純な形式では、以下のように大かっこの中にマッチングする文字を
5751089リストします: C<[aeiou]>.
5761090これは C<a>, C<e>, C<i>, C<o>, C<u> のどれかにマッチングします。
5771091他の文字クラスと同様、正確に一つの文字にマッチングします。
5781092文字クラスで言及した文字で構成されるより長い文字列にマッチングするには、
579文字クラスに量指定子を付けます。
1093文字クラスに L<量指定子|perlre/Quantifiers> を付けます。
580例えば、C<[aeiou]+> は一つまたはそれ以上の小文字 ASCII 母音に
1094例えば、C<[aeiou]+> は一つまたはそれ以上の小文字英語母音に
5811095マッチングします。
5821096
5831097=begin original
5841098
5851099Repeating a character in a character class has no
5861100effect; it's considered to be in the set only once.
5871101
5881102=end original
5891103
5901104文字クラスの中で文字を繰り返しても効果はありません; 一度だけ現れたものと
5911105考えられます。
5921106
5931107=begin original
5941108
5951109Examples:
5961110
5971111=end original
5981112
5991113例:
6001114
6011115=begin original
6021116
6031117 "e" =~ /[aeiou]/ # Match, as "e" is listed in the class.
6041118 "p" =~ /[aeiou]/ # No match, "p" is not listed in the class.
6051119 "ae" =~ /^[aeiou]$/ # No match, a character class only matches
6061120 # a single character.
6071121 "ae" =~ /^[aeiou]+$/ # Match, due to the quantifier.
6081122
6091123=end original
6101124
6111125 "e" =~ /[aeiou]/ # マッチング; "e" はクラスにある。
6121126 "p" =~ /[aeiou]/ # マッチングしない; "p" はクラスにない。
6131127 "ae" =~ /^[aeiou]$/ # マッチングしない; 一つの文字クラスは
6141128 # 一文字だけにマッチングする。
6151129 "ae" =~ /^[aeiou]+$/ # マッチング; 量指定子により。
6161130
1131 -------
1132
1133=begin original
1134
1135* There are two exceptions to a bracketed character class matching a
1136single character only. Each requires special handling by Perl to make
1137things work:
1138
1139=end original
1140
1141* 大かっこ文字クラスは単一の文字にのみマッチングするということには
1142二つの例外があります。
1143それぞれは Perl がうまく動くために特別な扱いが必要です:
1144
1145=over
1146
1147=item *
1148
1149=begin original
1150
1151When the class is to match caselessly under C</i> matching rules, and a
1152character that is explicitly mentioned inside the class matches a
1153multiple-character sequence caselessly under Unicode rules, the class
1154will also match that sequence. For example, Unicode says that the
1155letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss>
1156under C</i> rules. Thus,
1157
1158=end original
1159
1160クラスが C</i> マッチング規則の下で大文字小文字を無視したマッチングを
1161して、クラスの中で明示的に記述された文字が Unicode の規則の下で複数文字並びに
1162大文字小文字を無視してマッチングするとき、
1163そのクラスはその並びにもマッチングします。
1164例えば、Unicode は文字 C<LATIN SMALL LETTER SHARP S> は C</i> 規則の下では
1165並び C<ss> にマッチングするとしています。
1166従って:
1167
1168 'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i # Matches
1169 'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i # Matches
1170
1171=begin original
1172
1173For this to happen, the class must not be inverted (see L</Negation>)
1174and the character must be explicitly specified, and not be part of a
1175multi-character range (not even as one of its endpoints). (L</Character
1176Ranges> will be explained shortly.) Therefore,
1177
1178=end original
1179
1180これが起きるためには、
1181そのクラスは否定 (L</Negation> 参照) ではなく、
1182その文字は明示的に指定され、複数文字範囲の一部
1183(たとえその端でも)でない必要があります。
1184(L</Character Ranges> は短く説明されています。)
1185従って:
1186
1187 'ss' =~ /\A[\0-\x{ff}]\z/ui # Doesn't match
1188 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui # No match
1189 'ss' =~ /\A[\xDF-\xDF]\z/ui # Matches on ASCII platforms, since
1190 # \xDF is LATIN SMALL LETTER SHARP S,
1191 # and the range is just a single
1192 # element
1193
1194=begin original
1195
1196Note that it isn't a good idea to specify these types of ranges anyway.
1197
1198=end original
1199
1200どちらにしろこれらの種類の範囲を指定するのは良い考えではありません。
1201
1202=item *
1203
1204=begin original
1205
1206Some names known to C<\N{...}> refer to a sequence of multiple characters,
1207instead of the usual single character. When one of these is included in
1208the class, the entire sequence is matched. For example,
1209
1210=end original
1211
1212Some names known to
1213C<\N{...}> で知られているいくつかの名前は、通常の単一の文字ではなく、
1214複数の文字の並びを参照します。
1215その一つがこのクラスに含まれている場合、並び全体がマッチングします。
1216例えば:
1217
1218 "\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}"
1219 =~ / ^ [\N{TAMIL SYLLABLE KAU}] $ /x;
1220
1221=begin original
1222
1223matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence
1224consisting of the two characters matched against. Like the other
1225instance where a bracketed class can match multiple characters, and for
1226similar reasons, the class must not be inverted, and the named sequence
1227may not appear in a range, even one where it is both endpoints. If
1228these happen, it is a fatal error if the character class is within the
1229scope of L<C<use re 'strict>|re/'strict' mode>, or within an extended
1230L<C<(?[...])>|/Extended Bracketed Character Classes> class; otherwise
1231only the first code point is used (with a C<regexp>-type warning
1232raised).
1233
1234=end original
1235
1236これはマッチングします; なぜなら C<\N{TAMIL SYLLABLE KAU}> は
1237マッチングする二つの文字からなる名前付き並びだからです。
1238大かっこクラスが複数の文字にマッチングするその他の例と同じように、
1239そして同様の理由で、クラスは否定できず、
1240たとえ両端の間であっても名前付き並びは範囲の中には現れません。
1241これらが起きたとき、文字クラスが
1242L<C<use re 'strict>|re/'strict' mode> のスコープ内か、
1243拡張された L<C<(?[...])>|/Extended Bracketed Character Classes> クラスの
1244中の場合には致命的エラーになります;
1245さもなければ、最初の符号位置のみが使われます
1246(そして C<regexp> 系の警告が発生します)。
1247
1248=back
1249
6171250=head3 Special Characters Inside a Bracketed Character Class
6181251
6191252(かっこ付き文字クラスの中の特殊文字)
6201253
6211254=begin original
6221255
6231256Most characters that are meta characters in regular expressions (that
624is, characters that carry a special meaning like C<*> or C<(>) lose
1257is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
6251258their special meaning and can be used inside a character class without
6261259the need to escape them. For instance, C<[()]> matches either an opening
6271260parenthesis, or a closing parenthesis, and the parens inside the character
628class don't group or capture.
1261class don't group or capture. Be aware that, unless the pattern is
1262evaluated in single-quotish context, variable interpolation will take
1263place before the bracketed class is parsed:
6291264
6301265=end original
6311266
632正規表現内でメタ文字(つまり、C<*> C<(> のように特別な意味を持つ文字)となる
1267正規表現内でメタ文字(つまり、C<.>, C<*>, C<(> のように特別な意味を持つ
633ほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を失うので、
1268文字)となるほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を
634エスケープする必要はありません。
1269失うので、エスケープする必要はありません。
6351270例えば、C<[()]> は開きかっこまたは閉じかっこにマッチングし、文字クラスの中の
6361271かっこはグループや捕捉にはなりません。
1272パターンがシングルクォート風コンテキストの中で評価されない限り、
1273変数展開は大かっこクラスがパースされる前に行われることに注意してください:
6371274
1275 $, = "\t| ";
1276 $x =~ m'[$,]'; # single-quotish: matches '$' or ','
1277 $x =~ q{[$,]}' # same
1278 $x =~ m/[$,]/; # double-quotish: Because we made an
1279 # assignment to $, above, this now
1280 # matches "\t", "|", or " "
1281
6381282=begin original
6391283
6401284Characters that may carry a special meaning inside a character class are:
6411285C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
6421286escaped with a backslash, although this is sometimes not needed, in which
6431287case the backslash may be omitted.
6441288
6451289=end original
6461290
6471291文字クラスの中でも特別な意味を持つ文字は:
6481292C<\>, C<^>, C<->, C<[>, C<]> で、以下で議論します。
6491293これらは逆スラッシュでエスケープできますが、不要な場合もあり、そのような
6501294場合では逆スラッシュは省略できます。
6511295
6521296=begin original
6531297
6541298The sequence C<\b> is special inside a bracketed character class. While
655outside the character class C<\b> is an assertion indicating a point
1299outside the character class, C<\b> is an assertion indicating a point
6561300that does not have either two word characters or two non-word characters
6571301on either side, inside a bracketed character class, C<\b> matches a
6581302backspace character.
6591303
6601304=end original
6611305
6621306シーケンス C<\b> は大かっこ文字クラスの内側では特別です。
6631307文字クラスの外側では C<\b> 二つの単語文字か二つの非単語文字のどちらかではない
6641308位置を示す表明ですが、大かっこ文字クラスの内側では C<\b> は後退文字に
6651309マッチングします。
6661310
6671311=begin original
6681312
669A C<[> is not special inside a character class, unless it's the start
1313The sequences
670of a POSIX character class (see below). It normally does not need escaping.
1314C<\a>,
1315C<\c>,
1316C<\e>,
1317C<\f>,
1318C<\n>,
1319C<\N{I<NAME>}>,
1320C<\N{U+I<hex char>}>,
1321C<\r>,
1322C<\t>,
1323and
1324C<\x>
1325are also special and have the same meanings as they do outside a
1326bracketed character class.
6711327
6721328=end original
6731329
674C<[> は、POSIX 文字クラス(後述)の開始でない限りは文字クラスの中では
1330並び
675特別ではありません。
1331C<\a>,
1332C<\c>,
1333C<\e>,
1334C<\f>,
1335C<\n>,
1336C<\N{I<NAME>}>,
1337C<\N{U+I<hex char>}>,
1338C<\r>,
1339C<\t>,
1340C<\x>
1341も特別で、大かっこ文字クラスの外側と同じ意味を持ちます。
1342
1343=begin original
1344
1345Also, a backslash followed by two or three octal digits is considered an octal
1346number.
1347
1348=end original
1349
1350また、逆スラッシュに引き続いて 2 または 3 桁の 8 進数字があると 8 進数として
1351扱われます。
1352
1353=begin original
1354
1355A C<[> is not special inside a character class, unless it's the start of a
1356POSIX character class (see L</POSIX Character Classes> below). It normally does
1357not need escaping.
1358
1359=end original
1360
1361C<[> は、POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
1362開始でない限りは文字クラスの中では特別ではありません。
6761363これは普通エスケープは不要です。
6771364
6781365=begin original
6791366
680A C<]> is either the end of a POSIX character class (see below), or it
1367A C<]> is normally either the end of a POSIX character class (see
681signals the end of the bracketed character class. Normally it needs
1368L</POSIX Character Classes> below), or it signals the end of the bracketed
682escaping if you want to include a C<]> in the set of characters.
1369character class. If you want to include a C<]> in the set of characters, you
1370must generally escape it.
1371
1372=end original
1373
1374A C<]> は普通は POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の
1375終わりか、大かっこ文字クラスの終了を示すかどちらかです。
1376文字集合に C<]> を含める必要がある場合、一般的には
1377エスケープしなければなりません。
1378
1379=begin original
1380
6831381However, if the C<]> is the I<first> (or the second if the first
6841382character is a caret) character of a bracketed character class, it
6851383does not denote the end of the class (as you cannot have an empty class)
6861384and is considered part of the set of characters that can be matched without
6871385escaping.
6881386
6891387=end original
6901388
691A C<]> は POSIX 文字クラス(後述)の終わりか、大かっこ文字クラスの終了を
692示すかどちらかです。
693通常、文字集合に C<]> を含める場合はエスケープする必要があります。
6941389しかし、C<]> が大かっこ文字クラスの I<最初> (または最初の文字がキャレットなら
69513902 番目) の文字の場合、(空クラスを作ることはできないので)これはクラスの
6961391終了を意味せず、エスケープなしでマッチングできる文字の集合の一部と
6971392考えられます。
6981393
6991394=begin original
7001395
7011396Examples:
7021397
7031398=end original
7041399
7051400例:
7061401
7071402=begin original
7081403
7091404 "+" =~ /[+?*]/ # Match, "+" in a character class is not special.
7101405 "\cH" =~ /[\b]/ # Match, \b inside in a character class
711 # is equivalent with a backspace.
1406 # is equivalent to a backspace.
712 "]" =~ /[][]/ # Match, as the character class contains.
1407 "]" =~ /[][]/ # Match, as the character class contains
7131408 # both [ and ].
7141409 "[]" =~ /[[]]/ # Match, the pattern contains a character class
715 # containing just ], and the character class is
1410 # containing just [, and the character class is
7161411 # followed by a ].
7171412
7181413=end original
7191414
7201415 "+" =~ /[+?*]/ # マッチング; 文字クラス内の "+" は特別ではない。
7211416 "\cH" =~ /[\b]/ # マッチング; 文字クラスの内側の \b は後退と
7221417 # 等価。
7231418 "]" =~ /[][]/ # マッチング; 文字クラスに [ と ] の両方を
7241419 # 含んでいる。
725 "[]" =~ /[[]]/ # マッチング; パターンは ] だけを含んでいる
1420 "[]" =~ /[[]]/ # マッチング; パターンは [ だけを含んでいる
7261421 # 文字クラスと、それに引き続く
7271422 # ] からなる。
7281423
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
7291484=head3 Character Ranges
7301485
7311486(文字範囲)
7321487
7331488=begin original
7341489
7351490It is not uncommon to want to match a range of characters. Luckily, instead
736of listing all the characters in the range, one may use the hyphen (C<->).
1491of listing all characters in the range, one may use the hyphen (C<->).
7371492If inside a bracketed character class you have two characters separated
738by a hyphen, it's treated as if all the characters between the two are in
1493by a hyphen, it's treated as if all characters between the two were in
7391494the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]>
7401495matches any lowercase letter from the first half of the ASCII alphabet.
7411496
7421497=end original
7431498
7441499文字のある範囲にマッチングしたいというのは珍しくありません。
7451500幸運なことに、その範囲の文字を全て一覧に書く代わりに、ハイフン (C<->) を
7461501使えます。
7471502大かっこ文字クラスの内側で二つの文字がハイフンで区切られていると、
7481503二つの文字の間の全ての文字がクラスに書かれているかのように扱われます。
7491504例えば、C<[0-9]> は任意の ASCII 数字にマッチングし、C<[a-m]> は
7501505ASCII アルファベットの前半分の小文字にマッチングします。
7511506
7521507=begin original
7531508
7541509Note that the two characters on either side of the hyphen are not
755necessary both letters or both digits. Any character is possible,
1510necessarily both letters or both digits. Any character is possible,
7561511although not advisable. C<['-?]> contains a range of characters, but
757most people will not know which characters that will be. Furthermore,
1512most people will not know which characters that means. Furthermore,
7581513such ranges may lead to portability problems if the code has to run on
7591514a platform that uses a different character set, such as EBCDIC.
7601515
7611516=end original
7621517
7631518ハイフンのそれぞれの側の二つの文字は両方とも英字であったり両方とも
764数字であったりする必要はありませんが、勧められないことに注意してください。
1519数字であったりする必要はないことに注意してください。
1520任意の文字が可能ですが、勧められません。
7651521C<['-?]> は文字の範囲を含みますが、ほとんどの人はどの文字が含まれるか
7661522分かりません。
7671523さらに、このような範囲は、コードが EBCDIC のような異なった文字集合を使う
7681524プラットフォームで実行されると移植性の問題を引き起こします。
7691525
7701526=begin original
7711527
772If a hyphen in a character class cannot be part of a range, for instance
1528If a hyphen in a character class cannot syntactically be part of a range, for
773because it is the first or the last character of the character class,
1529instance because it is the first or the last character of the character class,
774or if it immediately follows a range, the hyphen isn't special, and will be
1530or if it immediately follows a range, the hyphen isn't special, and so is
775considered a character that may be matched. You have to escape the hyphen
1531considered a character to be matched literally. If you want a hyphen in
776with a backslash if you want to have a hyphen in your set of characters to
1532your set of characters to be matched and its position in the class is such
777be matched, and its position in the class is such that it can be considered
1533that it could be considered part of a range, you must escape that hyphen
778part of a range.
1534with a backslash.
7791535
7801536=end original
7811537
7821538例えば文字クラスの最初または最後であったり、範囲の直後のために、文字クラスの
783中のハイフンが範囲の一部となれない場合、ハイフンは特別ではなく、
1539中のハイフンが文法的に範囲の一部となれない場合、ハイフンは特別ではなく、
784マッチングするべき文字として扱われます。
1540リテラルにマッチングするべき文字として扱われます。
7851541マッチングする文字の集合にハイフンを入れたいけれどもその位置が範囲の
786一部として考えられる場合はハイフンを逆スラッシュでエスケープする
1542一部として考えられる場合はハイフンを逆スラッシュで
787必要がありま
1543エスケープしなければなりません
7881544
7891545=begin original
7901546
7911547Examples:
7921548
7931549=end original
7941550
7951551例:
7961552
7971553=begin original
7981554
7991555 [a-z] # Matches a character that is a lower case ASCII letter.
800 [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or the
1556 [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or
801 # letter 'z'.
1557 # the letter 'z'.
8021558 [-z] # Matches either a hyphen ('-') or the letter 'z'.
8031559 [a-f-m] # Matches any letter between 'a' and 'f' (inclusive), the
8041560 # hyphen ('-'), or the letter 'm'.
8051561 ['-?] # Matches any of the characters '()*+,-./0123456789:;<=>?
8061562 # (But not on an EBCDIC platform).
1563 [\N{APOSTROPHE}-\N{QUESTION MARK}]
1564 # Matches any of the characters '()*+,-./0123456789:;<=>?
1565 # even on an EBCDIC platform.
1566 [\N{U+27}-\N{U+3F}] # Same. (U+27 is "'", and U+3F is "?")
8071567
8081568=end original
8091569
8101570 [a-z] # 小文字 ASCII 英字にマッチング。
8111571 [a-fz] # 'a' から 'f' の英字およびと 'z' の英字に
8121572 # マッチング。
8131573 [-z] # ハイフン ('-') または英字 'z' にマッチング。
8141574 [a-f-m] # 'a' から 'f' の英字、ハイフン ('-')、英字 'm' に
8151575 # マッチング。
8161576 ['-?] # 文字 '()*+,-./0123456789:;<=>? のどれかにマッチング
8171577 # (しかし EBCDIC プラットフォームでは異なります)。
1578 [\N{APOSTROPHE}-\N{QUESTION MARK}]
1579 # たとえ EBCDIC プラットフォームでも '()*+,-./0123456789:;<=>?
1580 # のいずれかの文字にマッチング。
1581 [\N{U+27}-\N{U+3F}] # 同じ。 (U+27 は "'", U+3F は "?")
8181582
1583=begin original
1584
1585As the final two examples above show, you can achieve portability to
1586non-ASCII platforms by using the C<\N{...}> form for the range
1587endpoints. These indicate that the specified range is to be interpreted
1588using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match
1589C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>,
1590and C<\N{U+3F}>, whatever the native code point versions for those are.
1591These are called "Unicode" ranges. If either end is of the C<\N{...}>
1592form, the range is considered Unicode. A C<regexp> warning is raised
1593under C<S<"use re 'strict'">> if the other endpoint is specified
1594non-portably:
1595
1596=end original
1597
1598前述の最後の二つの例が示すように、範囲の端点に
1599C<\N{...}> 形式を使用することで、非 ASCII プラットフォームへの
1600移植性を実現できます。
1601これらは、指定された範囲が Unicode 値を使用して解釈されることを示しています;
1602したがって、C<[\N{U+27}-\N{U+3F}]>は、C<\N{U+27}>、C<\N{U+28}>、
1603C<\N{U+29}>、...、C<\N{U+3D}>、C<\N{U+3E}>、C<\N{U+3F}> に
1604マッチングすることを意味します;
1605これらのネイティブ符号位置のバージョンが何であっても一致します。
1606これらは "Unicode" 範囲と呼ばれます。
1607いずれかの端点が C<\N{...}> 形式の場合、範囲は Unicode と見なされます。
1608もう一方の端点が移植性がない形で指定されている場合、
1609C<S<"use re 'strict'">> の下で C<regexp> 警告が発生します:
1610
1611 [\N{U+00}-\x09] # Warning under re 'strict'; \x09 is non-portable
1612 [\N{U+00}-\t] # No warning;
1613
1614=begin original
1615
1616Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ...
1617C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a
1618mistake so the warning is raised (under C<re 'strict'>) for it.
1619
1620=end original
1621
1622前述の両方とも文字 C<\N{U+00}> C<\N{U+01}>, ...
1623C<\N{U+08}>, C<\N{U+09}> にマッチングしますが、
1624C<\x09> は誤りのように見えるので、
1625(C<re 'strict'> の下で) 警告が発生します。
1626
1627=begin original
1628
1629Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any
1630subranges of these match what an English-only speaker would expect them
1631to match on any platform. That is, C<[A-Z]> matches the 26 ASCII
1632uppercase letters;
1633C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10
1634digits. Subranges, like C<[h-k]>, match correspondingly, in this case
1635just the four letters C<"h">, C<"i">, C<"j">, and C<"k">. This is the
1636natural behavior on ASCII platforms where the code points (ordinal
1637values) for C<"h"> through C<"k"> are consecutive integers (0x68 through
16380x6B). But special handling to achieve this may be needed on platforms
1639with a non-ASCII native character set. For example, on EBCDIC
1640platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is
16410x91, and C<"k"> is 0x92. Perl specially treats C<[h-k]> to exclude the
1642seven code points in the gap: 0x8A through 0x90. This special handling is
1643only invoked when the range is a subrange of one of the ASCII uppercase,
1644lowercase, and digit ranges, AND each end of the range is expressed
1645either as a literal, like C<"A">, or as a named character (C<\N{...}>,
1646including the C<\N{U+...> form).
1647
1648=end original
1649
1650Perl はまた、範囲 C<A-Z>、C<a-z>、C<0-9>、およびこれらの部分範囲が、
1651英語のみの話者が一致すると予想する範囲とどのプラットフォームでも
1652一致することを保証します。
1653つまり、C<[A-Z]> はASCII の大文字 26 文字と一致します;
1654C<[a-z]> は小文字 26 文字と一致します;
1655C<[0-9]>は 10 の数字と一致します。
1656C<[h-k]> のような部分範囲もこれに対応して一致します;
1657この場合、4 文字 C<"h">、C<"i">、C<"j">、C<"k"> だけが一致します。
1658これは、C<"h"> から C<"k"> までの符号位置(序数値)が連続した
1659整数(0x68 から 0x6B)である ASCII プラットフォームでの自然な動作です。
1660しかし、非 ASCII ネイティブ文字集合を持つプラットフォームでは、
1661これを実現するための特別な処理が必要になるかもしれません。
1662たとえば、EBCDIC プラットフォームでは、C<"h"> のコードポイントは
16630x88、C<"i"> は 0x89、C<"j"> は 0x91、C<"k"> は 0x92 です。
1664Perl は C<[h-k]> を特別に扱い、隙間にある七つの符号位置
1665(0x8A から 0x90)を除外します。
1666この特殊処理は、範囲が ASCII の大文字、小文字、数字の範囲の
1667いずれかの部分範囲であり、範囲の両端が C<"A"> のようなリテラル
1668または名前付き文字(C<\N{...}>(C<\N{U+...> 形式を含む))として表現されている
1669場合にのみ呼び出されます。
1670
1671=begin original
1672
1673EBCDIC Examples:
1674
1675=end original
1676
1677EBCDIC の例:
1678
1679 [i-j] # Matches either "i" or "j"
1680 [i-\N{LATIN SMALL LETTER J}] # Same
1681 [i-\N{U+6A}] # Same
1682 [\N{U+69}-\N{U+6A}] # Same
1683 [\x{89}-\x{91}] # Matches 0x89 ("i"), 0x8A .. 0x90, 0x91 ("j")
1684 [i-\x{91}] # Same
1685 [\x{89}-j] # Same
1686 [i-J] # Matches, 0x89 ("i") .. 0xC1 ("J"); special
1687 # handling doesn't apply because range is mixed
1688 # case
1689
8191690=head3 Negation
8201691
8211692(否定)
8221693
8231694=begin original
8241695
8251696It is also possible to instead list the characters you do not want to
8261697match. You can do so by using a caret (C<^>) as the first character in the
827character class. For instance, C<[^a-z]> matches a character that is not a
1698character class. For instance, C<[^a-z]> matches any character that is not a
828lowercase ASCII letter.
1699lowercase ASCII letter, which therefore includes more than a million
1700Unicode code points. The class is said to be "negated" or "inverted".
8291701
8301702=end original
8311703
8321704代わりにマッチングしたくない文字の一覧を指定することも可能です。
8331705文字クラスの先頭の文字としてキャレット (C<^>) を使うことで実現します。
834例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします
1706例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします;
1707従って 100 万種類以上の Unicode 符号位置が含まれます。
1708このクラスは「否定」("negated") や「反転」("inverted")と呼ばれます。
8351709
8361710=begin original
8371711
8381712This syntax make the caret a special character inside a bracketed character
8391713class, but only if it is the first character of the class. So if you want
840to have the caret as one of the characters you want to match, you either
1714the caret as one of the characters to match, either escape the caret or
841have to escape the caret, or not list it first.
1715else don't list it first.
8421716
8431717=end original
8441718
8451719この文法はキャレットを大かっこ文字クラスの内側で特別な文字にしますが、
8461720クラスの最初の文字の場合のみです。
8471721それでマッチングしたい文字の一つでキャレットを使いたい場合、キャレットを
848エスケープするか、最初以外の位置に書く必要があります
1722エスケープするか、最初以外の位置に書いてださい
8491723
8501724=begin original
8511725
1726In inverted bracketed character classes, Perl ignores the Unicode rules
1727that normally say that named sequence, and certain characters should
1728match a sequence of multiple characters use under caseless C</i>
1729matching. Following those rules could lead to highly confusing
1730situations:
1731
1732=end original
1733
1734否定大かっこ文字クラスでは、通常は大文字小文字を無視した C</i> マッチングの
1735下では名前空間とある種の文字が複数の文字並びにマッチングするということを
1736Perl は無視します。
1737これらの規則に従うととても混乱する状況を引き起こすことになるからです:
1738
1739 "ss" =~ /^[^\xDF]+$/ui; # Matches!
1740
1741=begin original
1742
1743This should match any sequences of characters that aren't C<\xDF> nor
1744what C<\xDF> matches under C</i>. C<"s"> isn't C<\xDF>, but Unicode
1745says that C<"ss"> is what C<\xDF> matches under C</i>. So which one
1746"wins"? Do you fail the match because the string has C<ss> or accept it
1747because it has an C<s> followed by another C<s>? Perl has chosen the
1748latter. (See note in L</Bracketed Character Classes> above.)
1749
1750=end original
1751
1752これは C</i> の下では C<\xDF> または C<\xDF> にマッチングするもの以外の
1753任意の文字並びにマッチングするべきです。
1754C<"s"> は C<\xDF> ではありませんが、
1755C</i> の下では C<"ss"> は C<\xDF> がマッチングするものと Unicode は
1756言っています。
1757ではどちらが「勝つ」のでしょうか?
1758文字列は C<ss> だからマッチングに失敗するのでしょうか、
1759それともこれは C<s> の後にもう一つの C<s> があるから成功するのでしょうか?
1760Perl は後者を選択しました。
1761(前述の L</Bracketed Character Classes> を参照してください。)
1762
1763=begin original
1764
8521765Examples:
8531766
8541767=end original
8551768
8561769例:
8571770
8581771=begin original
8591772
8601773 "e" =~ /[^aeiou]/ # No match, the 'e' is listed.
8611774 "x" =~ /[^aeiou]/ # Match, as 'x' isn't a lowercase vowel.
8621775 "^" =~ /[^^]/ # No match, matches anything that isn't a caret.
8631776 "^" =~ /[x^]/ # Match, caret is not special here.
8641777
8651778=end original
8661779
8671780 "e" =~ /[^aeiou]/ # マッチングしない; 'e' がある。
8681781 "x" =~ /[^aeiou]/ # マッチング; 'x' は小文字の母音ではない。
8691782 "^" =~ /[^^]/ # マッチングしない; キャレット以外全てにマッチング。
8701783 "^" =~ /[x^]/ # マッチング; キャレットはここでは特別ではない。
8711784
8721785=head3 Backslash Sequences
8731786
8741787(逆スラッシュシーケンス)
8751788
8761789=begin original
8771790
878You can put a backslash sequence character class inside a bracketed character
1791You can put any backslash sequence character class (with the exception of
879class, and it will act just as if you put all the characters matched by
1792C<\N> and C<\R>) inside a bracketed character class, and it will act just
880the backslash sequence inside the character class. For instance,
1793as if you had put all characters matched by the backslash sequence inside the
881C<[a-f\d]> will match any digit, or any of the lowercase letters between
1794character class. For instance, C<[a-f\d]> matches any decimal digit, or any
882'a' and 'f' inclusive.
1795of the lowercase letters between 'a' and 'f' inclusive.
8831796
8841797=end original
8851798
886大かっこ文字クラスの中に逆スラッシュシーケンス文字クラスを置くことができ、
1799大かっこ文字クラスの中に(C<\N> と C<\R> を例外として)逆スラッシュシーケンス
887逆スラッシュシーケンスにマッチングする全ての文字を文字クラスの中に
1800文字クラスを置くことができ、逆スラッシュシーケンスにマッチングする全ての
888置いたかのように動作します。
1801文字を文字クラスの中に置いたかのように動作します。
889例えば、C<[a-f\d]> は任意の数字、あるいは 'a' から 'f' までの小文字に
1802例えば、C<[a-f\d]> は任意の 10 進数字、あるいは 'a' から 'f' までの小文字に
8901803マッチングします。
8911804
8921805=begin original
8931806
1807C<\N> within a bracketed character class must be of the forms C<\N{I<name>}>
1808or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines,
1809for the same reason that a dot C<.> inside a bracketed character class loses
1810its special meaning: it matches nearly anything, which generally isn't what you
1811want to happen.
1812
1813=end original
1814
1815大かっこ文字クラスの中のドット C<.> が特別な意味を持たないのと同じ理由で、
1816大かっこ文字クラスの中の C<\N> は C<\N{I<name>}> または
1817C<\N{U+I<hex char>}> の形式で、かつ非改行マッチング形式でない形でなければ
1818なりません: これはほとんど何でもマッチングするので、一般的には起こって
1819欲しいことではありません。
1820
1821=begin original
1822
8941823Examples:
8951824
8961825=end original
8971826
8981827例:
8991828
9001829=begin original
9011830
9021831 /[\p{Thai}\d]/ # Matches a character that is either a Thai
9031832 # character, or a digit.
9041833 /[^\p{Arabic}()]/ # Matches a character that is neither an Arabic
9051834 # character, nor a parenthesis.
9061835
9071836=end original
9081837
9091838 /[\p{Thai}\d]/ # タイ文字または数字の文字に
9101839 # マッチングする。
9111840 /[^\p{Arabic}()]/ # アラビア文字でもかっこでもない文字に
9121841 # マッチングする。
9131842
9141843=begin original
9151844
9161845Backslash sequence character classes cannot form one of the endpoints
917of a range.
1846of a range. Thus, you can't say:
9181847
9191848=end original
9201849
9211850逆スラッシュシーケンス文字クラスは範囲の端点の一つにはできません。
1851従って、以下のようにはできません:
9221852
923=head3 Posix Character Classes
1853 /[\p{Thai}-\d]/ # Wrong!
9241854
925(Posix 文字クラス)
1855=head3 POSIX Character Classes
1856X<character class> X<\p> X<\p{}>
1857X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph>
1858X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit>
9261859
1860(POSIX 文字クラス)
1861
9271862=begin original
9281863
929Posix character classes have the form C<[:class:]>, where I<class> is
1864POSIX character classes have the form C<[:class:]>, where I<class> is the
930name, and the C<[:> and C<:]> delimiters. Posix character classes appear
1865name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear
9311866I<inside> bracketed character classes, and are a convenient and descriptive
932way of listing a group of characters. Be careful about the syntax,
1867way of listing a group of characters.
9331868
9341869=end original
9351870
936Posix 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は
1871POSIX 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は
9371872デリミタです。
938Posix 文字クラスは大かっこ文字クラスの I<内側> に現れ、文字のグループを
1873POSIX 文字クラスは大かっこ文字クラスの I<内側> にのみ現れ、文字のグループを
9391874一覧するのに便利で記述的な方法です。
1875
1876=begin original
1877
1878Be careful about the syntax,
1879
1880=end original
1881
9401882文法について注意してください、
9411883
9421884 # Correct:
9431885 $string =~ /[[:alpha:]]/
9441886
9451887 # Incorrect (will warn):
9461888 $string =~ /[:alpha:]/
9471889
9481890=begin original
9491891
9501892The latter pattern would be a character class consisting of a colon,
9511893and the letters C<a>, C<l>, C<p> and C<h>.
1894POSIX character classes can be part of a larger bracketed character class.
1895For example,
9521896
9531897=end original
9541898
9551899後者のパターンは、コロンおよび C<a>, C<l>, C<p>, C<h> の文字からなる
9561900文字クラスです。
1901これら文字クラスはより大きな大かっこ文字クラスの一部にできます。
1902例えば:
9571903
1904 [01[:alpha:]%]
1905
9581906=begin original
9591907
960Perl recognizes the following POSIX character classes:
1908is valid and matches '0', '1', any alphabetic character, and the percent sign.
9611909
9621910=end original
9631911
964Perl 以下 POSIX 文字クラスを認識します:
1912これは妥当で、'0'、'1'、任意、パーセントマーにマッチングします
9651913
9661914=begin original
9671915
968 alpha Any alphabetical character.
1916Perl recognizes the following POSIX character classes:
969 alnum Any alphanumerical character.
970 ascii Any ASCII character.
971 blank A GNU extension, equal to a space or a horizontal tab ("\t").
972 cntrl Any control character.
973 digit Any digit, equivalent to "\d".
974 graph Any printable character, excluding a space.
975 lower Any lowercase character.
976 print Any printable character, including a space.
977 punct Any punctuation character.
978 space Any white space character. "\s" plus the vertical tab ("\cK").
979 upper Any uppercase character.
980 word Any "word" character, equivalent to "\w".
981 xdigit Any hexadecimal digit, '0' - '9', 'a' - 'f', 'A' - 'F'.
9821917
9831918=end original
9841919
985 alpha 任意
1920Perl は以下 POSIX 文クラスを認識します:
986 alnum 任意の英数字。
987 ascii 任意の ASCII 文字。
988 blank GNU 拡張; スペースまたは水平タブ ("\t") と同じ。
989 cntrl 任意の制御文字。
990 digit 任意の数字; "\d" と等価。
991 graph 任意の表示文字; スペースを除く。
992 lower 任意の小文字。
993 print 任意の表示文字; スペースを含む。
994 punct 任意の句読点文字。
995 space 任意の空白文字。"\s" に加えて水平タブ ("\cK")。
996 upper 任意の大文字。
997 word 任意の「単語」文字; "\w" と等価。
998 xdigit 任意の 16 進文字; '0' - '9', 'a' - 'f', 'A' - 'F'。
9991921
10001922=begin original
10011923
1002The exact set of characters matched depends on whether the source string
1924 alpha Any alphabetical character (e.g., [A-Za-z]).
1003is internally in UTF-8 format or not. See L</Locale, Unicode and UTF-8>.
1925 alnum Any alphanumeric character (e.g., [A-Za-z0-9]).
1926 ascii Any character in the ASCII character set.
1927 blank Any horizontal whitespace character (e.g. space or horizontal
1928 tab ("\t")).
1929 cntrl Any control character. See Note [2] below.
1930 digit Any decimal digit (e.g., [0-9]), equivalent to "\d".
1931 graph Any printable character, excluding a space. See Note [3] below.
1932 lower Any lowercase character (e.g., [a-z]).
1933 print Any printable character, including a space. See Note [4] below.
1934 punct Any graphical character excluding "word" characters. Note [5].
1935 space Any whitespace character. "\s" including the vertical tab
1936 ("\cK").
1937 upper Any uppercase character (e.g., [A-Z]).
1938 word A Perl extension (e.g., [A-Za-z0-9_]), equivalent to "\w".
1939 xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]). Note [7].
10041940
10051941=end original
10061942
1007マッチングする文字正確な集合はソース文列が内部で UTF-8 形式かどうかに
1943 alpha 任意(例: [A-Za-z])。
1008依存します
1944 alnum 任意の英数字(例: [A-Za-z0-9])
1009L</Locale, Unicode and UTF-8> を参照してください
1945 ascii 任意の ASCII 文字集合の文字
1946 blank 任意の水平空白文字 (スペース、水平タブ ("\t") など)
1947 cntrl 任意の制御文字。後述の [2] 参照。
1948 digit 任意の 10 進数字 (例: [0-9]); "\d" と等価。
1949 graph 任意の表示文字; スペースを除く。後述の [3] 参照。
1950 lower 任意の小文字 (例: [a-z])。
1951 print 任意の表示文字; スペースを含む。後述の [4] 参照。
1952 punct 任意の「単語」文字を除く表示文字。[5] 参照。
1953 space 任意の空白文字。水平タブ ("\cK") を含む "\s"。
1954 upper 任意の大文字 (例: [A-Z])。
1955 word Perl 拡張 (例: [A-Za-z0-9_]); "\w" と等価。
1956 xdigit 任意の 16 進文字 (例: [0-9a-fA-F])。[7] 参照。
10101957
10111958=begin original
10121959
1013Most POSIX character classes have C<\p> counterparts. The difference
1960Like the L<Unicode properties|/Unicode Properties>, most of the POSIX
1014is that the C<\p> classes will always match according to the Unicode
1961properties match the same regardless of whether case-insensitive (C</i>)
1015properties, regardless whether the string is in UTF-8 format or not.
1962matching is in effect or not. The two exceptions are C<[:upper:]> and
1963C<[:lower:]>. Under C</i>, they each match the union of C<[:upper:]> and
1964C<[:lower:]>.
10161965
10171966=end original
10181967
1019ほとんどの POSIX 文字クラスは対応する C<\p> を持っています。
1968L<Unicode properties|/Unicode Properties> と同様、
1020違いは、文字列が UTF-8 形式かどうかに関わらず C<\p> クラスは常に
1969ほとんどの POSIX 特性は、文字小文字無視 (C</i>) が有効かどうかに関わらず
1021Unicode 特性従ってマッチングするということです。
1970同じものにマッチングします。
1971二つの例外は C<[:upper:]> と C<[:lower:]> です。
1972C</i> の下では、これらそれぞれ C<[:upper:]> と C<[:lower:]> の和集合に
1973マッチングします。
10221974
10231975=begin original
10241976
1025The following table shows the relation between POSIX character classes
1977Most POSIX character classes have two Unicode-style C<\p> property
1026and the Unicode properties:
1978counterparts. (They are not official Unicode properties, but Perl extensions
1979derived from official Unicode properties.) The table below shows the relation
1980between POSIX character classes and these counterparts.
10271981
10281982=end original
10291983
1030以下表は POSIX 文字クラス Unicode 特性との関係を示しています:
1984ほとんどの POSIX 文字クラスには、対応する二つの Unicode 式の C<\p> 特性
1985あります。
1986(これは公式 Unicode 特性ではなく、公式 Unicode 特性から派生した Perl
1987エクステンションです。)
1988以下の表は POSIX 文字クラスと対応するものとの関連を示します。
10311989
1032 [[:...:]] \p{...} backslash
1990=begin original
10331991
1034 alpha IsAlpha
1992One counterpart, in the column labelled "ASCII-range Unicode" in
1035 alnum IsAlnum
1993the table, matches only characters in the ASCII character set.
1036 ascii IsASCII
1037 blank
1038 cntrl IsCntrl
1039 digit IsDigit \d
1040 graph IsGraph
1041 lower IsLower
1042 print IsPrint
1043 punct IsPunct
1044 space IsSpace
1045 IsSpacePerl \s
1046 upper IsUpper
1047 word IsWord
1048 xdigit IsXDigit
10491994
1995=end original
1996
1997対応物の一つである、表で "ASCII-range Unicode" と書かれた列のものは、
1998ASCII 文字集合の文字にのみマッチングします。
1999
10502000=begin original
10512001
1052Some character classes may have a non-obvious name:
2002The other counterpart, in the column labelled "Full-range Unicode", matches any
2003appropriate characters in the full Unicode character set. For example,
2004C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any
2005character in the entire Unicode character set considered alphabetic.
2006An entry in the column labelled "backslash sequence" is a (short)
2007equivalent.
10532008
10542009=end original
10552010
1056文字クラスは明らかない名前を持ちます:
2011もう対応物ある、"Full-range Unicode" と書かれた列のものは、
2012Unicode 文字集合全体の中の適切な任意の文字にマッチングします。
2013例えば、C<\p{Alpha}> は単に ASCII アルファベット文字だけでなく、
2014Unicode 文字集合全体の中からアルファベットと考えられる任意の文字に
2015マッチングします。
2016"backslash sequence" の列は (短い) 同義語です。
10572017
2018 [[:...:]] ASCII-range Full-range backslash Note
2019 Unicode Unicode sequence
2020 -----------------------------------------------------
2021 alpha \p{PosixAlpha} \p{XPosixAlpha}
2022 alnum \p{PosixAlnum} \p{XPosixAlnum}
2023 ascii \p{ASCII}
2024 blank \p{PosixBlank} \p{XPosixBlank} \h [1]
2025 or \p{HorizSpace} [1]
2026 cntrl \p{PosixCntrl} \p{XPosixCntrl} [2]
2027 digit \p{PosixDigit} \p{XPosixDigit} \d
2028 graph \p{PosixGraph} \p{XPosixGraph} [3]
2029 lower \p{PosixLower} \p{XPosixLower}
2030 print \p{PosixPrint} \p{XPosixPrint} [4]
2031 punct \p{PosixPunct} \p{XPosixPunct} [5]
2032 \p{PerlSpace} \p{XPerlSpace} \s [6]
2033 space \p{PosixSpace} \p{XPosixSpace} [6]
2034 upper \p{PosixUpper} \p{XPosixUpper}
2035 word \p{PosixWord} \p{XPosixWord} \w
2036 xdigit \p{PosixXDigit} \p{XPosixXDigit} [7]
2037
10582038=over 4
10592039
1060=item cntrl
2040=item [1]
10612041
10622042=begin original
10632043
1064Any control character. Usually, control characters don't produce output
2044C<\p{Blank}> and C<\p{HorizSpace}> are synonyms.
1065as such, but instead control the terminal somehow: for example newline
1066and backspace are control characters. All characters with C<ord()> less
1067than 32 are usually classified as control characters (in ASCII, the ISO
1068Latin character sets, and Unicode), as is the character C<ord()> value
1069of 127 (C<DEL>).
10702045
10712046=end original
10722047
1073任意の制御文字
2048C<\p{Blank}> と C<\p{HorizSpace}> は同義語です
1074普通は、制御文字はそれ自体は出力されず、何か端末を制御します: 例えば
2050=item [2]
2051
2052=begin original
2053
2054Control characters don't produce output as such, but instead usually control
2055the terminal somehow: for example, newline and backspace are control characters.
2056On ASCII platforms, in the ASCII range, characters whose code points are
2057between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on
2058EBCDIC platforms, their counterparts are control characters.
2059
2060=end original
2061
2062制御文字はそれ自体は出力されず、普通は何か端末を制御します: 例えば
10752063改行と後退は制御文字です。
1076(ASCII、ISO Latin 文字集合Unicode) C<ord()> 32 未満全ての文字および
2064ASCII プラットフォームでASCII の範囲では符号位置が 0 から 31 まで
1077C<ord()> 値が 127 の文字 (C<DEL>) は普通は制御文字に分類されま
2065範囲の文字および 127 (C<DEL>) 制御文字;
2066EBCDIC プラットフォームでは、対応するものは制御文字です。
10782067
1079=item graph
2068=item [3]
10802069
10812070=begin original
10822071
10832072Any character that is I<graphical>, that is, visible. This class consists
1084of all the alphanumerical characters and all punctuation characters.
2073of all alphanumeric characters and all punctuation characters.
10852074
10862075=end original
10872076
10882077I<graphical>、つまり見える文字。
10892078このクラスは全ての英数字と全ての句読点文字。
10902079
1091=item print
2080=item [4]
10922081
10932082=begin original
10942083
1095All printable characters, which is the set of all the graphical characters
2084All printable characters, which is the set of all graphical characters
1096plus the space.
2085plus those whitespace characters which are not also controls.
10972086
10982087=end original
10992088
1100全ての表示可能な文字; 全ての graphical 文字空白。
2089全ての表示可能な文字; 全ての graphical 文字に加えて制御文字でない空白文字
11012090
1102=item punct
2091=item [5]
11032092
11042093=begin original
11052094
1106Any punctuation (special) character.
2095C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all
2096non-controls, non-alphanumeric, non-space characters:
2097C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect,
2098it could alter the behavior of C<[[:punct:]]>).
11072099
11082100=end original
11092101
1110任意句読点(特殊)文
2102ASCII 範囲の C<\p{PosixPunct}> と C<[[:punct:]]> は全ての非制御、非英数
2103非空白文字にマッチングします:
2104C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (しかしロケールが有効なら、
2105C<[[:punct:]]> の振る舞いが変わります)。
11112106
2107=begin original
2108
2109The similarly named property, C<\p{Punct}>, matches a somewhat different
2110set in the ASCII range, namely
2111C<[-!"#%&'()*,./:;?@[\\\]_{}]>. That is, it is missing the nine
2112characters C<[$+E<lt>=E<gt>^`|~]>.
2113This is because Unicode splits what POSIX considers to be punctuation into two
2114categories, Punctuation and Symbols.
2115
2116=end original
2117
2118似たような名前の特性 C<\p{Punct}> は、ASCII 範囲の異なる集合である
2119C<[-!"#%&'()*,./:;?@[\\\]_{}]> にマッチングします。
2120つまり、C<[$+E<lt>=E<gt>^`|~]> の 9 文字はありません。
2121これは、Unicode は POSIX が句読点と考えるものを二つのカテゴリ
2122Punctuation と Symbols に分けているからです。
2123
2124=begin original
2125
2126C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what
2127C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}>
2128matches. This is different than strictly matching according to
2129C<\p{Punct}>. Another way to say it is that
2130if Unicode rules are in effect, C<[[:punct:]]> matches all characters
2131that Unicode considers punctuation, plus all ASCII-range characters that
2132Unicode considers symbols.
2133
2134=end original
2135
2136C<\p{XPosixPunct}> と (Unicode の規則の下での) C<[[:punct:]]> は、
2137ASCII の範囲で C<\p{PosixPunct}> がマッチングする物に加えて、
2138C<\p{Punct}> がマッチングする物にマッチングします。
2139これは C<\p{Punct}> に従って正確にマッチングする物と異なります。
2140Unicode 規則が有効な場合のもう一つの言い方は、C<[[:punct:]]> は Unicode が
2141句読点として扱うものに加えて、Unicode が "symbols" として扱う ASCII 範囲の
2142全ての文字にマッチングします。
2143
2144=item [6]
2145
2146=begin original
2147
2148C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl
2149v5.18. In earlier versions, these differ only in that in non-locale
2150matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>.
2151Same for the two ASCII-only range forms.
2152
2153=end original
2154
2155C<\p{XPerlSpace}> と C<\p{Space}> は、Perl v5.18 からは同じように
2156マッチングします。
2157以前のバージョンでは、これらの違いは、非ロケールマッチングでは
2158C<\p{XPerlSpace}> は垂直タブ C<\cK> にもマッチングしないということだけです。
2159二つの ASCII のみの範囲の形式では同じです。
2160
2161=item [7]
2162
2163=begin original
2164
2165Unlike C<[[:digit:]]> which matches digits in many writing systems, such
2166as Thai and Devanagari, there are currently only two sets of hexadecimal
2167digits, and it is unlikely that more will be added. This is because you
2168not only need the ten digits, but also the six C<[A-F]> (and C<[a-f]>)
2169to correspond. That means only the Latin script is suitable for these,
2170and Unicode has only two sets of these, the familiar ASCII set, and the
2171fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO).
2172
2173=end original
2174
2175タイ文字やデバナーガリ文字のように多くの書記体系の数字にマッチングする
2176C<[[:digit:]]> と異なり、16 進数の二つの集合だけで、これ以上追加されることは
2177おそらくありません。
2178これは、対応するのに 10 の数字だけでなく、6 個の C<[A-F]> (および C<[a-f]>) も
2179必要だからです。
2180これは、Latin 用字のみがこれらに適合していて、
2181Unicode はこれらの二つの集合、つまり慣れ親しんだ
2182ASCII 集合と、U+FF10 (FULLWIDTH DIGIT ZERO) から始まる全角形式のみを
2183持つということです。
2184
11122185=back
11132186
1114=head4 Negation
2187=begin original
11152188
1116(否定)
2189There are various other synonyms that can be used besides the names
2190listed in the table. For example, C<\p{XPosixAlpha}> can be written as
2191C<\p{Alpha}>. All are listed in
2192L<perluniprops/Properties accessible through \p{} and \P{}>.
11172193
2194=end original
2195
2196表に挙げられている名前以外にも様々なその他の同義語が使えます。
2197例えば、C<\p{XPosixAlpha}> は C<\p{Alpha}> と書けます。
2198全ての一覧は
2199L<perluniprops/Properties accessible through \p{} and \P{}> に
2200あります。
2201
11182202=begin original
11192203
2204Both the C<\p> counterparts always assume Unicode rules are in effect.
2205On ASCII platforms, this means they assume that the code points from 128
2206to 255 are Latin-1, and that means that using them under locale rules is
2207unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the
2208POSIX character classes are useful under locale rules. They are
2209affected by the actual rules in effect, as follows:
2210
2211=end original
2212
2213C<\p> に対応するものの両方は常に Unicode の規則が有効であることを仮定します。
2214これは、ASCII プラットフォームでは、128 から 255 の符号位置は
2215Latin-1 であることを仮定するということで、ロケールの規則の下で
2216これらを使うということは、ロケールが Latin-1 か UTF-8 であることが
2217補償されていない限り賢明ではないということです。
2218一方、POSIX 文字クラスはロケールの規則の下で有用です。
2219これらは次のように、実際に有効な規則に影響を受けます:
2220
2221=over
2222
2223=item If the C</a> modifier, is in effect ...
2224
2225(C</a> が有効なら...)
2226
2227=begin original
2228
2229Each of the POSIX classes matches exactly the same as their ASCII-range
2230counterparts.
2231
2232=end original
2233
2234それぞれの POSIX クラスは ASCII の範囲で対応する正確に同じものに
2235マッチングします。
2236
2237=item otherwise ...
2238
2239(さもなければ ...)
2240
2241=over
2242
2243=item For code points above 255 ...
2244
2245(256 以上の符号位置では ...)
2246
2247=begin original
2248
2249The POSIX class matches the same as its Full-range counterpart.
2250
2251=end original
2252
2253POSIX クラスはその Full の範囲で対応する同じものにマッチングします。
2254
2255=item For code points below 256 ...
2256
2257(255 以下の符号位置では ...)
2258
2259=over
2260
2261=item if locale rules are in effect ...
2262
2263(ロケール規則が有効なら ...)
2264
2265=begin original
2266
2267The POSIX class matches according to the locale, except:
2268
2269=end original
2270
2271POSIX クラスはロケールに従ってマッチングします; 例外は:
2272
2273=over
2274
2275=item C<word>
2276
2277=begin original
2278
2279also includes the platform's native underscore character, no matter what
2280the locale is.
2281
2282=end original
2283
2284それに加えて、ロケールが何かに関わらず、プラットフォームのネイティブな
2285下線文字を使います。
2286
2287=item C<ascii>
2288
2289=begin original
2290
2291on platforms that don't have the POSIX C<ascii> extension, this matches
2292just the platform's native ASCII-range characters.
2293
2294=end original
2295
2296POSIX C<ascii> 拡張を持たないプラットフォームでは、
2297これは単にプラットフォームのネイティブな ASCII の範囲の文字に
2298マッチングします。
2299
2300=item C<blank>
2301
2302=begin original
2303
2304on platforms that don't have the POSIX C<blank> extension, this matches
2305just the platform's native tab and space characters.
2306
2307=end original
2308
2309on platforms that don't have the
2310POSIX C<blank> 格調を持たないプラットフォームでは、
2311これは単にプラットフォームのネイティブなタブとすぺーす文字に
2312マッチングします。
2313
2314=back
2315
2316=item if, instead, Unicode rules are in effect ...
2317
2318(そうではなく、Unicode 規則が有効なら ...)
2319
2320=begin original
2321
2322The POSIX class matches the same as the Full-range counterpart.
2323
2324=end original
2325
2326POSIX クラスは Full の範囲の対応する同じものにマッチングします。
2327
2328=item otherwise ...
2329
2330(さもなければ ...)
2331
2332=begin original
2333
2334The POSIX class matches the same as the ASCII range counterpart.
2335
2336=end original
2337
2338POSIX クラスは ASCII の範囲の同じものにマッチングします。
2339
2340=back
2341
2342=back
2343
2344=back
2345
2346=begin original
2347
2348Which rules apply are determined as described in
2349L<perlre/Which character set modifier is in effect?>.
2350
2351=end original
2352
2353どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
2354記述されている方法で決定されます。
2355
2356=head4 Negation of POSIX character classes
2357X<character class, negation>
2358
2359(POSIX 文字クラスの否定)
2360
2361=begin original
2362
11202363A Perl extension to the POSIX character class is the ability to
11212364negate it. This is done by prefixing the class name with a caret (C<^>).
11222365Some examples:
11232366
11242367=end original
11252368
11262369POSIX 文字クラスに対する Perl の拡張は否定の機能です。
11272370これはクラス名の前にキャレット (C<^>) を置くことで実現します。
11282371いくつかの例です:
11292372
1130 POSIX Unicode Backslash
2373 POSIX ASCII-range Full-range backslash
1131 [[:^digit:]] \P{IsDigit} \D
2374 Unicode Unicode sequence
1132 [[:^space:]] \P{IsSpace} \S
2375 -----------------------------------------------------
1133 [[:^word:]] \P{IsWord} \W
2376 [[:^digit:]] \P{PosixDigit} \P{XPosixDigit} \D
2377 [[:^space:]] \P{PosixSpace} \P{XPosixSpace}
2378 \P{PerlSpace} \P{XPerlSpace} \S
2379 [[:^word:]] \P{PerlWord} \P{XPosixWord} \W
11342380
2381=begin original
2382
2383The backslash sequence can mean either ASCII- or Full-range Unicode,
2384depending on various factors as described in L<perlre/Which character set modifier is in effect?>.
2385
2386=end original
2387
2388逆スラッシュシーケンスは ASCII- か Full-range Unicode のどちらかを意味します;
2389どちらが使われるかは L<perlre/Which character set modifier is in effect?> で
2390記述されている様々な要素に依存します。
2391
11352392=head4 [= =] and [. .]
11362393
11372394([= =] と [. .])
11382395
11392396=begin original
11402397
1141Perl will recognize the POSIX character classes C<[=class=]>, and
2398Perl recognizes the POSIX character classes C<[=class=]> and
1142C<[.class.]>, but does not (yet?) support this construct. Use of
2399C<[.class.]>, but does not (yet?) support them. Any attempt to use
1143such a construct will lead to an error.
2400either construct raises an exception.
11442401
11452402=end original
11462403
11472404Perl は POSIX 文字クラス C<[=class=]> と C<[.class.]> を認識しますが、
1148これらの構文には(まだ?)対応していません。
2405これらには(まだ?)対応していません。
1149このような構文の使用はエラー引き起こします。
2406このような構文を使おうとすると例外が発生します。
11502407
11512408=head4 Examples
11522409
11532410(例)
11542411
11552412=begin original
11562413
11572414 /[[:digit:]]/ # Matches a character that is a digit.
11582415 /[01[:lower:]]/ # Matches a character that is either a
11592416 # lowercase letter, or '0' or '1'.
1160 /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything,
2417 /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
1161 # but the letters 'a' to 'f' in either case.
2418 # except the letters 'a' to 'f' and 'A' to
1162 # This is because the character class contains
2419 # 'F'. This is because the main character
1163 # all digits, and anything that isn't a
2420 # class is composed of two POSIX character
1164 # hex digit, resulting in a class containing
2421 # classes that are ORed together, one that
1165 # all characters, but the letters 'a' to 'f'
2422 # matches any digit, and the other that
1166 # and 'A' to 'F'.
2423 # matches anything that isn't a hex digit.
2424 # The OR adds the digits, leaving only the
2425 # letters 'a' to 'f' and 'A' to 'F' excluded.
11672426
11682427=end original
11692428
11702429 /[[:digit:]]/ # 数字の文字にマッチングする。
11712430 /[01[:lower:]]/ # 小文字、'0'、'1' のいずれかの文字に
11722431 # マッチングする。
1173 /[[:digit:][:^xdigit:]]/ # どんな文字にもマッチングしますが、大文字小文字の
2432 /[[:digit:][:^xdigit:]]/ # 'a' から 'f' と 'A' から 'F' 以外の任意の文字に
1174 # 'a' から 'f' を除きます
2433 # マッチングこれはメインの文字クラスでは二つの
1175 # れは全ての数字と 16 進文字でない全ての文字を
2434 # POSIX 文字クラスが OR さ、一つ任意の数字
1176 # 含む文字クラスなので、このクラスには
2435 # マッチングし、もう一つは 16 進文字い全て
1177 # 'a' から 'f' および 'A' から 'F'
2436 # 文字にマッチングします。OR は数字加え、
1178 # 除く全て文字に
2437 # 'a' から 'f' および 'A' から 'F' みが
1179 # マッチングすることになります。
2438 # 除外されて残ります。
11802439
1181=head2 Locale, Unicode and UTF-8
2440=head3 Extended Bracketed Character Classes
2441X<character class>
2442X<set operations>
11822443
1183(ロケール、Unicode、UTF-8)
2444(拡張大かっこ文字クラス)
11842445
11852446=begin original
11862447
1187Some of the character classes have a somewhat different behaviour depending
2448This is a fancy bracketed character class that can be used for more
1188on the internal encoding of the source string, and the locale that is
2449readable and less error-prone classes, and to perform set operations,
1189in effect.
2450such as intersection. An example is
11902451
11912452=end original
11922453
1193ソース文字列の内部ンコディングと有効なロケールに依存て少し異なった
2454これはしゃれた大かっこ文字クラスで、より読みやすく、が発生にくい
1194振る舞いをする文字クラスもあります。
2455クラスや、交差などの集合演算を実行するために使用できます。
2456例は:
11952457
2458 /(?[ \p{Thai} & \p{Digit} ])/
2459
11962460=begin original
11972461
1198C<\w>, C<\d>, C<\s> and the POSIX character classes (and their negations,
2462This will match all the digit characters that are in the Thai script.
1199including C<\W>, C<\D>, C<\S>) suffer from this behaviour.
12002463
12012464=end original
12022465
1203C<\w>, C<\d>, C<\s> および POSIX 文字クラ (および C<\W>, C<\D>, C<\S> を
2466これは、タイ語クリプト内のすべての数字と一致します。
1204含むこれらの否定) はこの振る舞いの影響を受けます。
12052467
12062468=begin original
12072469
1208The rule is that if the source string is in UTF-8 format, the character
2470This feature became available in Perl 5.18, as experimental; accepted in
1209classes match according to the Unicode properties. If the source string
24715.36.
1210isn't, then the character classes match according to whatever locale is
1211in effect. If there is no locale, they match the ASCII defaults
1212(52 letters, 10 digits and underscore for C<\w>, 0 to 9 for C<\d>, etc).
12132472
12142473=end original
12152474
1216ソース文字列が UTF-8 形式なら、文字クラスUnicode 特性従って
2475この機能Perl 5.18 で実験的利用可能になりました;
1217マッチングするという規則
24765.36 受け入れられました
1218ソース文字列が UTF-8 形式ではなければ、文字クラスはロケールが
1219有効かどうかに従ってマッチングします。
1220ロケールがなければ、ASCII のデフォルト (C<\w> では 52 の英字、10 の数字と
1221下線、C<\d> では 0 から 9など) にマッチングします。
12222477
12232478=begin original
12242479
1225This usually means that if you are matching against characters whose C<ord()>
2480The rules used by L<C<use re 'strict>|re/'strict' mode> apply to this
1226values are between 128 and 255 inclusive, your character class may match
2481construct.
1227or not depending on the current locale, and whether the source string is
1228in UTF-8 format. The string will be in UTF-8 format if it contains
1229characters whose C<ord()> value exceeds 255. But a string may be in UTF-8
1230format without it having such characters.
12312482
12322483=end original
12332484
1234これは普通、C<ord()> の値が 128 から 255 の範囲のマッチングするなら、
2485L<C<use re 'strict>|re/'strict' mode> で使われる規則はこ文に
1235その文字クラスは現在のロケールおよびソース文字列が UTF-8 形式かどうかに
2486適用されます。
1236依存してマッチングしたりしなかったりします。
1237C<ord()> 値が 255 を超える文字が含まれているなら文字列は UTF-8 形式です。
1238しかしそのような文字がなくても UTF-8 形式かもしれません。
12392487
12402488=begin original
12412489
1242For portability reasons, it may be better to not use C<\w>, C<\d>, C<\s>
2490We can extend the example above:
1243or the POSIX character classes, and use the Unicode properties instead.
12442491
12452492=end original
12462493
1247移植性理由により、C<\w>, C<\d>, C<\s> や POSIX 文字クラスは使わず、
2494上記例を拡張できます:
1248Unicode 特性を使う方が良いです。
12492495
1250=head4 Examples
2496 /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/
12512497
1252(例)
2498=begin original
12532499
2500This matches digits that are in either the Thai or Laotian scripts.
2501
2502=end original
2503
2504これはタイ語またはラオス語のいずれかの数字と一致します。
2505
12542506=begin original
12552507
1256 $str = "\xDF"; # $str is not in UTF-8 format.
2508Notice the white space in these examples. This construct always has
1257 $str =~ /^\w/; # No match, as $str isn't in UTF-8 format.
2509the C<E<sol>xx> modifier turned on within it.
1258 $str .= "\x{0e0b}"; # Now $str is in UTF-8 format.
1259 $str =~ /^\w/; # Match! $str is now in UTF-8 format.
1260 chop $str;
1261 $str =~ /^\w/; # Still a match! $str remains in UTF-8 format.
12622510
12632511=end original
12642512
1265 $str = "\xDF"; # $str は UTF-8 形式ではない。
2513これらの例の中の空白に注意してください。
1266 $str =~ /^\w/; # マッチグしない; $str は UTF-8 形式ではない
2514この構文では、その中では常に C<E<sol>xx> 修飾子がオってます
1267 $str .= "\x{0e0b}"; # ここで $str は UTF-8 形式。
1268 $str =~ /^\w/; # マッチング! $str は UTF-8 形式。
1269 chop $str;
1270 $str =~ /^\w/; # まだマッチング! $str は UTF-8 形式のまま。
12712515
2516=begin original
2517
2518The available binary operators are:
2519
2520=end original
2521
2522使用可能な 2 項演算子は次のとおりです:
2523
2524 & intersection
2525 + union
2526 | another name for '+', hence means union
2527 - subtraction (the result matches the set consisting of those
2528 code points matched by the first operand, excluding any that
2529 are also matched by the second operand)
2530 ^ symmetric difference (the union minus the intersection). This
2531 is like an exclusive or, in that the result is the set of code
2532 points that are matched by either, but not both, of the
2533 operands.
2534
2535=begin original
2536
2537There is one unary operator:
2538
2539=end original
2540
2541単項演算子が一つあります。
2542
2543 ! complement
2544
2545=begin original
2546
2547All the binary operators left associate; C<"&"> is higher precedence
2548than the others, which all have equal precedence. The unary operator
2549right associates, and has highest precedence. Thus this follows the
2550normal Perl precedence rules for logical operators. Use parentheses to
2551override the default precedence and associativity.
2552
2553=end original
2554
2555すべての二項演算子は左結合です; C<"&"> はその他よりも高い優先順位を持ち、
2556それ以外は同等の優先順位を持ちます。
2557単項演算子は右結合で、最も高い優先順位を持ちます。
2558従って、これは通常の Perl の論理演算子に関する優先順位規則に従います。
2559デフォルトの優先順位と結合を上書きするにはかっこを使います。
2560
2561=begin original
2562
2563The main restriction is that everything is a metacharacter. Thus,
2564you cannot refer to single characters by doing something like this:
2565
2566=end original
2567
2568主な制限は、すべてがメタ文字であるということです。
2569したがって、以下のようにして単一文字を参照することはできません:
2570
2571 /(?[ a + b ])/ # Syntax error!
2572
2573=begin original
2574
2575The easiest way to specify an individual typable character is to enclose
2576it in brackets:
2577
2578=end original
2579
2580タイプ可能な個々の文字を指定する最も簡単な方法は、次のように
2581かっこで囲むことです:
2582
2583 /(?[ [a] + [b] ])/
2584
2585=begin original
2586
2587(This is the same thing as C<[ab]>.) You could also have said the
2588equivalent:
2589
2590=end original
2591
2592(これはC<[ab]>と同じことです)。
2593同じことを言うこともできます:
2594
2595 /(?[[ a b ]])/
2596
2597=begin original
2598
2599(You can, of course, specify single characters by using, C<\x{...}>,
2600C<\N{...}>, etc.)
2601
2602=end original
2603
2604(もちろん、C<\x{...}> や C<\N{...}> などを使用して 1 文字を
2605指定することもできます。)
2606
2607=begin original
2608
2609This last example shows the use of this construct to specify an ordinary
2610bracketed character class without additional set operations. Note the
2611white space within it. This is allowed because C<E<sol>xx> is
2612automatically turned on within this construct.
2613
2614=end original
2615
2616この最後の例では、この構文を使用して、追加の集合操作なしで
2617通常の大かっこ文字クラスを指定する方法を示しています。
2618この中に空白があることに注意してください。
2619C<E<sol>xx> は、この構文の内側で自動的に有効になるのでこれが許されます。
2620
2621=begin original
2622
2623All the other escapes accepted by normal bracketed character classes are
2624accepted here as well.
2625
2626=end original
2627
2628通常の大かっこ文字クラスで受け入れられる他のエスケープは
2629すべてここでも受け入れられます。
2630
2631=begin original
2632
2633Because this construct compiles under
2634L<C<use re 'strict>|re/'strict' mode>, unrecognized escapes that
2635generate warnings in normal classes are fatal errors here, as well as
2636all other warnings from these class elements, as well as some
2637practices that don't currently warn outside C<re 'strict'>. For example
2638you cannot say
2639
2640=end original
2641
2642この構文は L<C<use re 'strict>|re/'strict' mode> の下でコンパイルされるので、
2643通常のクラスで警告を生成する
2644認識されないエスケープはここでは致命的なエラーです;
2645これらのクラス要素からのその他すべての警告も同様で、
2646C<re 'strict'> の外側では、現在警告していないいくつかのプラクティスも
2647同様です。
2648例えば次のようにはできません:
2649
2650 /(?[ [ \xF ] ])/ # Syntax error!
2651
2652=begin original
2653
2654You have to have two hex digits after a braceless C<\x> (use a leading
2655zero to make two). These restrictions are to lower the incidence of
2656typos causing the class to not match what you thought it would.
2657
2658=end original
2659
2660中かっこのない C<\x> の後には 2 桁の 16 進数が必要です(2 桁にするには
2661先頭の 0 を使用します)。
2662これらの制限は、クラスが想定したものと一致しない原因となる
2663タイプミスの発生を減らすためです。
2664
2665=begin original
2666
2667If a regular bracketed character class contains a C<\p{}> or C<\P{}> and
2668is matched against a non-Unicode code point, a warning may be
2669raised, as the result is not Unicode-defined. No such warning will come
2670when using this extended form.
2671
2672=end original
2673
2674通常の大かっこ文字クラスに C<\p{}> や C<\P{}> が含まれていて、
2675非 Unicode 符号位置に対してマッチングした場合、
2676結果は Unicode で定義されていないので、警告が発生します。
2677このような警告は、拡張形式を使った場合は発生しません。
2678
2679=begin original
2680
2681The final difference between regular bracketed character classes and
2682these, is that it is not possible to get these to match a
2683multi-character fold. Thus,
2684
2685=end original
2686
2687通常の大かっこ文字クラスとこれらのクラスの最後の違いは、
2688これらを複数文字畳み込みにマッチングさせることができないということです。
2689従って:
2690
2691 /(?[ [\xDF] ])/iu
2692
2693=begin original
2694
2695does not match the string C<ss>.
2696
2697=end original
2698
2699は文字列 C<ss> と一致しません。
2700
2701=begin original
2702
2703You don't have to enclose POSIX class names inside double brackets,
2704hence both of the following work:
2705
2706=end original
2707
2708POSIX クラス名を二重かっこで囲む必要はありません;
2709そのため、以下の両方とも動作します:
2710
2711 /(?[ [:word:] - [:lower:] ])/
2712 /(?[ [[:word:]] - [[:lower:]] ])/
2713
2714=begin original
2715
2716Any contained POSIX character classes, including things like C<\w> and C<\D>
2717respect the C<E<sol>a> (and C<E<sol>aa>) modifiers.
2718
2719=end original
2720
2721C<\w> や C<\D> などの POSIX 文字クラスは、C<E<sol>a>
2722(および C<E<sol>aa> )修飾子を尊重します。
2723
2724=begin original
2725
2726Note that C<< (?[ ]) >> is a regex-compile-time construct. Any attempt
2727to use something which isn't knowable at the time the containing regular
2728expression is compiled is a fatal error. In practice, this means
2729just three limitations:
2730
2731=end original
2732
2733C<< (?[ ]) >> は コンパイル時正規表現構文であることに注意してください。
2734正規表現を含むコンパイル時に未知のものを使用しようとすると、
2735致命的なエラーになります。
2736実際には、これは三つの制限を意味します:
2737
2738=over 4
2739
2740=item 1
2741
2742=begin original
2743
2744When compiled within the scope of C<use locale> (or the C<E<sol>l> regex
2745modifier), this construct assumes that the execution-time locale will be
2746a UTF-8 one, and the generated pattern always uses Unicode rules. What
2747gets matched or not thus isn't dependent on the actual runtime locale, so
2748tainting is not enabled. But a C<locale> category warning is raised
2749if the runtime locale turns out to not be UTF-8.
2750
2751=end original
2752
2753C<use locale> (または C<E<sol>l> 正規表現修飾子)の
2754スコープ内でコンパイルされると、この構文は実行時ロケールが
2755UTF-8 のものであることを仮定し、
2756生成されたパターンは常に Unicode の規則を使います。
2757従ってマッチングするかどうかは実際の実行時ロケールには関係なく、
2758汚染チェックモードは有効になりません。
2759しかし、実行時ロケールが UTF-8 以外になると、
2760C<locale> カテゴリの警告が発生します。
2761
2762=item 2
2763
2764=begin original
2765
2766Any
2767L<user-defined property|perlunicode/"User-Defined Character Properties">
2768used must be already defined by the time the regular expression is
2769compiled (but note that this construct can be used instead of such
2770properties).
2771
2772=end original
2773
2774使用される
2775L<ユーザー定義特性|perlunicode/"User-Defined Character Properties"> は、
2776正規表現がコンパイルされるときにすでに定義されている必要があります
2777(ただし、このような特性の代わりにこの構文を使用することもできます)。
2778
2779=item 3
2780
2781=begin original
2782
2783A regular expression that otherwise would compile
2784using C<E<sol>d> rules, and which uses this construct will instead
2785use C<E<sol>u>. Thus this construct tells Perl that you don't want
2786C<E<sol>d> rules for the entire regular expression containing it.
2787
2788=end original
2789
2790C<E<sol>d> 規則を使用してコンパイルされ、この構文を使用する正規表現は、
2791代わりに C<E<sol>u> を使用します。
2792したがって、この構文は、C<E<sol>d> 規則が含まれている
2793正規表現全体に対して C<E<sol>d> 規則が必要ないことを Perl に通知します。
2794
2795=back
2796
2797=begin original
2798
2799Note that skipping white space applies only to the interior of this
2800construct. There must not be any space between any of the characters
2801that form the initial C<(?[>. Nor may there be space between the
2802closing C<])> characters.
2803
2804=end original
2805
2806空白のスキップは、この構造体の内部にのみ適用されることに注意してください。
2807最初の C<(?[> を形成する文字の間に空白を入れることはできません。
2808また、終わりの C<])> 文字の間に空白を入れることもできません。
2809
2810=begin original
2811
2812Just as in all regular expressions, the pattern can be built up by
2813including variables that are interpolated at regex compilation time.
2814But currently each such sub-component should be an already-compiled
2815extended bracketed character class.
2816
2817=end original
2818
2819すべての正規表現と同様に、正規表現コンパイル時に補完される変数を
2820含めることでパターンを構築できます。
2821しかし、現在の所、このような部分要素のそれぞれは
2822すでにコンパイルされた拡張大かっこ文字クラスであるべきです。
2823
2824 my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
2825 ...
2826 qr/(?[ \p{Digit} & $thai_or_lao ])/;
2827
2828=begin original
2829
2830If you interpolate something else, the pattern may still compile (or it
2831may die), but if it compiles, it very well may not behave as you would
2832expect:
2833
2834=end original
2835
2836何か違うものを変数展開すると、パターンはやはりコンパイルされます
2837(あるいは die します)が、コンパイルされると、想像しているものと
2838かなり違う振る舞いになるかもしれません:
2839
2840 my $thai_or_lao = '\p{Thai} + \p{Lao}';
2841 qr/(?[ \p{Digit} & $thai_or_lao ])/;
2842
2843=begin original
2844
2845compiles to
2846
2847=end original
2848
2849これは次のようにコンパイルされます:
2850
2851 qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
2852
2853=begin original
2854
2855This does not have the effect that someone reading the source code
2856would likely expect, as the intersection applies just to C<\p{Thai}>,
2857excluding the Laotian.
2858
2859=end original
2860
2861これは、ソースコードを読んでいる人が期待するような効果はありません;
2862なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には
2863適用されないからです。
2864
2865=begin original
2866
2867Due to the way that Perl parses things, your parentheses and brackets
2868may need to be balanced, even including comments. If you run into any
2869examples, please submit them to L<https://github.com/Perl/perl5/issues>,
2870so that we can have a concrete example for this man page.
2871
2872=end original
2873
2874Perl の構文解析方法によっては、コメントを含めてもかっこと大かっこの
2875バランスを取る必要がある場合があります。
2876もし何か例を見つけたら、L<https://github.com/Perl/perl5/issues> に
2877登録してください;
2878そうすれば、この man ページの具体的な例を得ることができます。
2879
12722880=begin meta
12732881
1274Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1)
2882Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1-)
12752883Status: completed
12762884
12772885=end meta
1278
1279=cut