perlrecharclass >
5.18.1
との差分
perlrecharclass 5.18.1 と 5.40.0 の差分
| 1 | 1 | |
| 2 | =encoding | |
| 2 | =encoding utf8 | |
| 3 | 3 | |
| 4 | 4 | =head1 NAME |
| 5 | 5 | X<character class> |
| 6 | 6 | |
| 7 | 7 | =begin original |
| 8 | 8 | |
| 9 | 9 | perlrecharclass - Perl Regular Expression Character Classes |
| 10 | 10 | |
| 11 | 11 | =end original |
| 12 | 12 | |
| 13 | 13 | perlrecharclass - Perl 正規表現文字クラス |
| 14 | 14 | |
| 15 | 15 | =head1 DESCRIPTION |
| 16 | 16 | |
| 17 | 17 | =begin original |
| 18 | 18 | |
| 19 | 19 | The top level documentation about Perl regular expressions |
| 20 | 20 | is found in L<perlre>. |
| 21 | 21 | |
| 22 | 22 | =end original |
| 23 | 23 | |
| 24 | 24 | Perl 正規表現に関する最上位文書は L<perlre> です。 |
| 25 | 25 | |
| 26 | 26 | =begin original |
| 27 | 27 | |
| 28 | 28 | This manual page discusses the syntax and use of character |
| 29 | 29 | classes in Perl regular expressions. |
| 30 | 30 | |
| 31 | 31 | =end original |
| 32 | 32 | |
| 33 | 33 | このマニュアルページは Perl 正規表現の文字クラスの文法と使用法について |
| 34 | 34 | 議論します。 |
| 35 | 35 | |
| 36 | 36 | =begin original |
| 37 | 37 | |
| 38 | 38 | A character class is a way of denoting a set of characters |
| 39 | 39 | in such a way that one character of the set is matched. |
| 40 | 40 | It's important to remember that: matching a character class |
| 41 | 41 | consumes exactly one character in the source string. (The source |
| 42 | 42 | string is the string the regular expression is matched against.) |
| 43 | 43 | |
| 44 | 44 | =end original |
| 45 | 45 | |
| 46 | 46 | 文字クラスは、集合の中の一文字がマッチングするというような方法で、 |
| 47 | 47 | 文字の集合を指定するための方法です。 |
| 48 | 48 | 次のことを覚えておくことは重要です: 文字集合はソース文字列の中から正確に |
| 49 | 49 | 一文字だけを消費します。 |
| 50 | 50 | (ソース文字列とは正規表現がマッチングしようとしている文字列です。) |
| 51 | 51 | |
| 52 | 52 | =begin original |
| 53 | 53 | |
| 54 | 54 | There are three types of character classes in Perl regular |
| 55 | 55 | expressions: the dot, backslash sequences, and the form enclosed in square |
| 56 | 56 | brackets. Keep in mind, though, that often the term "character class" is used |
| 57 | 57 | to mean just the bracketed form. Certainly, most Perl documentation does that. |
| 58 | 58 | |
| 59 | 59 | =end original |
| 60 | 60 | |
| 61 | 61 | Perl 正規表現には 3 種類の文字クラスがあります: ドット、 |
| 62 | 62 | 逆スラッシュシーケンス、大かっこで囲まれた形式です。 |
| 63 | 63 | しかし、「文字クラス」という用語はしばしば大かっこ形式だけを意味するために |
| 64 | 64 | 使われることに注意してください。 |
| 65 | 65 | 確かに、ほとんどの Perl 文書ではそうなっています。 |
| 66 | 66 | |
| 67 | 67 | =head2 The dot |
| 68 | 68 | |
| 69 | 69 | (ドット) |
| 70 | 70 | |
| 71 | 71 | =begin original |
| 72 | 72 | |
| 73 | 73 | The dot (or period), C<.> is probably the most used, and certainly |
| 74 | 74 | the most well-known character class. By default, a dot matches any |
| 75 | 75 | character, except for the newline. That default can be changed to |
| 76 | add matching the newline by using the I<single line> modifier: | |
| 76 | add matching the newline by using the I<single line> modifier: | |
| 77 | 77 | for the entire regular expression with the C</s> modifier, or |
| 78 | locally with C<(?s)> | |
| 78 | locally with C<(?s)> (and even globally within the scope of | |
| 79 | L<C<use re '/s'>|re/'E<sol>flags' mode>). (The C<L</\N>> backslash | |
| 80 | sequence, described | |
| 79 | 81 | below, matches any character except newline without regard to the |
| 80 | 82 | I<single line> modifier.) |
| 81 | 83 | |
| 82 | 84 | =end original |
| 83 | 85 | |
| 84 | 86 | ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に |
| 85 | 87 | もっともよく知られている文字クラスです。 |
| 86 | 88 | デフォルトでは、ドットは改行を除く任意の文字にマッチングします。 |
| 87 | 89 | このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように |
| 88 | 90 | 変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには |
| 89 | C<(?s)> を使います | |
| 91 | C<(?s)> を使います | |
| 90 | ( | |
| 92 | (そしてグローバルに L<C<use re '/s'>|re/'E<sol>flags' mode> の | |
| 93 | スコープ内の場合でもそうです)。 | |
| 94 | (後述する C<L</\N>> 逆スラッシュシーケンスでは、I<単一行> 修飾子に | |
| 91 | 95 | 関わりなく改行以外の任意の文字にマッチングします。) |
| 92 | 96 | |
| 93 | 97 | =begin original |
| 94 | 98 | |
| 95 | 99 | Here are some examples: |
| 96 | 100 | |
| 97 | 101 | =end original |
| 98 | 102 | |
| 99 | 103 | 以下は例です: |
| 100 | 104 | |
| 101 | 105 | =begin original |
| 102 | 106 | |
| 103 | 107 | "a" =~ /./ # Match |
| 104 | 108 | "." =~ /./ # Match |
| 105 | 109 | "" =~ /./ # No match (dot has to match a character) |
| 106 | 110 | "\n" =~ /./ # No match (dot does not match a newline) |
| 107 | 111 | "\n" =~ /./s # Match (global 'single line' modifier) |
| 108 | 112 | "\n" =~ /(?s:.)/ # Match (local 'single line' modifier) |
| 109 | 113 | "ab" =~ /^.$/ # No match (dot matches one character) |
| 110 | 114 | |
| 111 | 115 | =end original |
| 112 | 116 | |
| 113 | 117 | "a" =~ /./ # マッチングする |
| 114 | 118 | "." =~ /./ # マッチングする |
| 115 | 119 | "" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある) |
| 116 | 120 | "\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない) |
| 117 | 121 | "\n" =~ /./s # マッチングする (グローバル「単一行」修飾子) |
| 118 | 122 | "\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子) |
| 119 | 123 | "ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする) |
| 120 | 124 | |
| 121 | 125 | =head2 Backslash sequences |
| 122 | 126 | X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P> |
| 123 | 127 | X<\N> X<\v> X<\V> X<\h> X<\H> |
| 124 | 128 | X<word> X<whitespace> |
| 125 | 129 | |
| 126 | 130 | (逆スラッシュシーケンス) |
| 127 | 131 | |
| 128 | 132 | =begin original |
| 129 | 133 | |
| 130 | 134 | A backslash sequence is a sequence of characters, the first one of which is a |
| 131 | 135 | backslash. Perl ascribes special meaning to many such sequences, and some of |
| 132 | 136 | these are character classes. That is, they match a single character each, |
| 133 | 137 | provided that the character belongs to the specific set of characters defined |
| 134 | 138 | by the sequence. |
| 135 | 139 | |
| 136 | 140 | =end original |
| 137 | 141 | |
| 138 | 142 | 逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。 |
| 139 | 143 | Perl はそのような並びの多くに特別な意味を持たせていて、 |
| 140 | 144 | その一部は文字クラスです。 |
| 141 | 145 | つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に |
| 142 | 146 | 帰属する一文字にマッチングします。 |
| 143 | 147 | |
| 144 | 148 | =begin original |
| 145 | 149 | |
| 146 | 150 | Here's a list of the backslash sequences that are character classes. They |
| 147 | 151 | are discussed in more detail below. (For the backslash sequences that aren't |
| 148 | 152 | character classes, see L<perlrebackslash>.) |
| 149 | 153 | |
| 150 | 154 | =end original |
| 151 | 155 | |
| 152 | 156 | 以下は文字クラスの逆スラッシュシーケンスの一覧です。 |
| 153 | 157 | 以下でさらに詳細に議論します。 |
| 154 | 158 | (文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を |
| 155 | 159 | 参照してください。) |
| 156 | 160 | |
| 157 | 161 | =begin original |
| 158 | 162 | |
| 159 | 163 | \d Match a decimal digit character. |
| 160 | 164 | \D Match a non-decimal-digit character. |
| 161 | 165 | \w Match a "word" character. |
| 162 | 166 | \W Match a non-"word" character. |
| 163 | 167 | \s Match a whitespace character. |
| 164 | 168 | \S Match a non-whitespace character. |
| 165 | 169 | \h Match a horizontal whitespace character. |
| 166 | 170 | \H Match a character that isn't horizontal whitespace. |
| 167 | 171 | \v Match a vertical whitespace character. |
| 168 | 172 | \V Match a character that isn't vertical whitespace. |
| 169 | 173 | \N Match a character that isn't a newline. |
| 170 | 174 | \pP, \p{Prop} Match a character that has the given Unicode property. |
| 171 | 175 | \PP, \P{Prop} Match a character that doesn't have the Unicode property |
| 172 | 176 | |
| 173 | 177 | =end original |
| 174 | 178 | |
| 175 | 179 | \d 10 進数字にマッチング。 |
| 176 | 180 | \D 非 10 進数字にマッチング。 |
| 177 | 181 | \w 「単語」文字にマッチング。 |
| 178 | 182 | \W 非「単語」文字にマッチング。 |
| 179 | 183 | \s 空白文字にマッチング。 |
| 180 | 184 | \S 非空白文字にマッチング。 |
| 181 | 185 | \h 水平空白文字にマッチング。 |
| 182 | 186 | \H 水平空白でない文字にマッチング。 |
| 183 | 187 | \v 垂直空白文字にマッチング。 |
| 184 | 188 | \V 垂直空白でない文字にマッチング。 |
| 185 | 189 | \N 改行以外の文字にマッチング。 |
| 186 | 190 | \pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。 |
| 187 | 191 | \PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。 |
| 188 | 192 | |
| 189 | 193 | =head3 \N |
| 190 | 194 | |
| 191 | 195 | =begin original |
| 192 | 196 | |
| 193 | 197 | C<\N>, available starting in v5.12, like the dot, matches any |
| 194 | 198 | character that is not a newline. The difference is that C<\N> is not influenced |
| 195 | 199 | by the I<single line> regular expression modifier (see L</The dot> above). Note |
| 196 | 200 | that the form C<\N{...}> may mean something completely different. When the |
| 197 | 201 | C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline |
| 198 | 202 | character that many times. For example, C<\N{3}> means to match 3 |
| 199 | 203 | non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}> |
| 200 | 204 | is not a legal quantifier, it is presumed to be a named character. See |
| 201 | 205 | L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and |
| 202 | 206 | C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose |
| 203 | 207 | names are respectively C<COLON>, C<4F>, and C<F4>. |
| 204 | 208 | |
| 205 | 209 | =end original |
| 206 | 210 | |
| 207 | 211 | v5.12 から利用可能な C<\N> は、ドットのように、 |
| 208 | 212 | 改行以外の任意の文字にマッチングします。 |
| 209 | 213 | 違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです |
| 210 | 214 | (上述の L</The dot> 参照)。 |
| 211 | 215 | C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに |
| 212 | 216 | 注意してください。 |
| 213 | 217 | C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の |
| 214 | 218 | 非改行文字にマッチングします。 |
| 215 | 219 | 例えば、C<\N{3}> は三つの非改行にマッチングします; |
| 216 | 220 | C<\N{5,}> は五つ以上の非改行にマッチングします。 |
| 217 | 221 | しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と |
| 218 | 222 | 推定されます。 |
| 219 | 223 | これについては L<charnames> を参照してください。 |
| 220 | 224 | 例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な |
| 221 | 225 | 量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の |
| 222 | 226 | 文字を探そうとします。 |
| 223 | 227 | |
| 224 | 228 | =head3 Digits |
| 225 | 229 | |
| 226 | 230 | (数字) |
| 227 | 231 | |
| 228 | 232 | =begin original |
| 229 | 233 | |
| 230 | 234 | C<\d> matches a single character considered to be a decimal I<digit>. |
| 231 | 235 | If the C</a> regular expression modifier is in effect, it matches [0-9]. |
| 232 | 236 | Otherwise, it |
| 233 | 237 | matches anything that is matched by C<\p{Digit}>, which includes [0-9]. |
| 234 | 238 | (An unlikely possible exception is that under locale matching rules, the |
| 235 | current locale might not have [0-9] matched by C<\d>, and/or might match | |
| 239 | current locale might not have C<[0-9]> matched by C<\d>, and/or might match | |
| 236 | other characters whose code point is less than 256. | |
| 240 | other characters whose code point is less than 256. The only such locale | |
| 237 | definition would be | |
| 241 | definitions that are legal would be to match C<[0-9]> plus another set of | |
| 238 | ||
| 242 | 10 consecutive digit characters; anything else would be in violation of | |
| 243 | the C language standard, but Perl doesn't currently assume anything in | |
| 244 | regard to this.) | |
| 239 | 245 | |
| 240 | 246 | =end original |
| 241 | 247 | |
| 242 | 248 | C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。 |
| 243 | 249 | C</a> 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。 |
| 244 | さもなければ、これは [0-9] を含む、C<\p{Digit}> にマッチングするものに | |
| 250 | さもなければ、これは C<[0-9]> を含む、C<\p{Digit}> にマッチングするものに | |
| 245 | 251 | マッチングします。 |
| 246 | 252 | (ありそうもない例外はロケールマッチングの下で、現在のロケールが |
| 247 | 253 | C<\d> にマッチングする [0-9] がないか、 |
| 248 | 254 | 符号位置が 256 未満の他の文字にマッチングすることです。 |
| 249 | ||
| 255 | 唯一正当なロケール定義は、C<[0-9]> に加えてもう一つの 10 の連続した | |
| 256 | 数字の集合にマッチングするもので、 | |
| 257 | それ以外は C 言語標準に違反していますが、 | |
| 250 | 258 | Perl は今のところこれに関して何も仮定しません。) |
| 251 | 259 | |
| 252 | 260 | =begin original |
| 253 | 261 | |
| 254 | 262 | What this means is that unless the C</a> modifier is in effect C<\d> not |
| 255 | 263 | only matches the digits '0' - '9', but also Arabic, Devanagari, and |
| 256 | 264 | digits from other languages. This may cause some confusion, and some |
| 257 | 265 | security issues. |
| 258 | 266 | |
| 259 | 267 | =end original |
| 260 | 268 | |
| 261 | 269 | これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字 |
| 262 | 270 | '0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の |
| 263 | 271 | 数字もマッチングします。 |
| 264 | 272 | これは混乱やセキュリティ問題を引き起こすことがあります。 |
| 265 | 273 | |
| 266 | 274 | =begin original |
| 267 | 275 | |
| 268 | 276 | Some digits that C<\d> matches look like some of the [0-9] ones, but |
| 269 | 277 | have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks |
| 270 | very much like an ASCII DIGIT EIGHT (U+0038) | |
| 278 | very 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 | |
| 280 | application that | |
| 271 | 281 | is expecting only the ASCII digits might be misled, or if the match is |
| 272 | 282 | C<\d+>, the matched string might contain a mixture of digits from |
| 273 | 283 | different writing systems that look like they signify a number different |
| 274 | 284 | than they actually do. L<Unicode::UCD/num()> can |
| 275 | 285 | be used to safely |
| 276 | 286 | calculate the value, returning C<undef> if the input string contains |
| 277 | such a mixture. | |
| 287 | such a mixture. Otherwise, for example, a displayed price might be | |
| 288 | deliberately different than it appears. | |
| 278 | 289 | |
| 279 | 290 | =end original |
| 280 | 291 | |
| 281 | 292 | C<\d> にマッチングする数字には、[0-9] のように見えるけれども、 |
| 282 | 293 | 異なる値を持つものもあります。 |
| 283 | 例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038) | |
| 294 | 例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038) に | |
| 295 | とてもよく似ていて、 | |
| 296 | LEPCHA DIGIT SIX (U+1C46) は ASCII DIGIT FIVE (U+0035) に | |
| 284 | 297 | とてもよく似ています。 |
| 285 | 298 | ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、 |
| 286 | 299 | マッチングが C<\d+> の場合、 |
| 287 | 300 | マッチングした文字列は、実際と異なる値を示しているように見える、 |
| 288 | 301 | 異なった書記体系からの数字が混ざったものかもしれません。 |
| 289 | 302 | L<Unicode::UCD/num()> は値を安全に計算するのに使えます; |
| 290 | 303 | 入力文字列がこのような混合を含んでいる場合は C<undef> を返します。 |
| 304 | さもなければ、例えば、表示された価格は見た目と意図的に違うものに | |
| 305 | なるかもしれません。 | |
| 291 | 306 | |
| 292 | 307 | =begin original |
| 293 | 308 | |
| 294 | 309 | What C<\p{Digit}> means (and hence C<\d> except under the C</a> |
| 295 | 310 | modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously, |
| 296 | 311 | C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this |
| 297 | 312 | is the same set of characters matched by C<\p{Numeric_Type=Decimal}>. |
| 298 | 313 | But Unicode also has a different property with a similar name, |
| 299 | 314 | C<\p{Numeric_Type=Digit}>, which matches a completely different set of |
| 300 | 315 | characters. These characters are things such as C<CIRCLED DIGIT ONE> |
| 301 | 316 | or subscripts, or are from writing systems that lack all ten digits. |
| 302 | 317 | |
| 303 | 318 | =end original |
| 304 | 319 | |
| 305 | 320 | C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、 |
| 306 | 321 | C<\p{General_Category=Decimal_Number}>、または同義語として |
| 307 | 322 | C<\p{General_Category=Digit}> です。 |
| 308 | 323 | Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に |
| 309 | 324 | マッチングする文字集合と同じです。 |
| 310 | 325 | ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ |
| 311 | 326 | 別の特性もあります; これは完全に異なる文字集合とマッチングします。 |
| 312 | 327 | これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、 |
| 313 | 328 | 10 の数字すべてが揃っていない書記体系からのものです。 |
| 314 | 329 | |
| 315 | 330 | =begin original |
| 316 | 331 | |
| 317 | 332 | The design intent is for C<\d> to exactly match the set of characters |
| 318 | 333 | that can safely be used with "normal" big-endian positional decimal |
| 319 | 334 | syntax, where, for example 123 means one 'hundred', plus two 'tens', |
| 320 | 335 | plus three 'ones'. This positional notation does not necessarily apply |
| 321 | 336 | to characters that match the other type of "digit", |
| 322 | 337 | C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them. |
| 323 | 338 | |
| 324 | 339 | =end original |
| 325 | 340 | |
| 326 | 341 | 設計意図は、C<\d> が「通常の」ビッグエンディアンの |
| 327 | 342 | 位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を |
| 328 | 343 | 加えたものを意味する) で安全に使用できる文字集合と |
| 329 | 正確にマッチングするようにすることです | |
| 344 | 正確にマッチングするようにすることです。 | |
| 330 | 345 | この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に |
| 331 | 346 | マッチングする文字には必ずしも適用されないため、 |
| 332 | 347 | C<\d> はこれらの文字にマッチングしません。 |
| 333 | 348 | |
| 334 | 349 | =begin original |
| 335 | 350 | |
| 336 | 351 | The Tamil digits (U+0BE6 - U+0BEF) can also legally be |
| 337 | 352 | used in old-style Tamil numbers in which they would appear no more than |
| 338 | 353 | one in a row, separated by characters that mean "times 10", "times 100", |
| 339 | etc. (See L<http://www.unicode.org/notes/tn21>.) | |
| 354 | etc. (See L<https://www.unicode.org/notes/tn21>.) | |
| 340 | 355 | |
| 341 | 356 | =end original |
| 342 | 357 | |
| 343 | 358 | タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の |
| 344 | 359 | 数字でも合法的に使用することができます; |
| 345 | 360 | この数字は、「×10」や「×100」などを意味する文字で区切られて、 |
| 346 | 361 | 1 回に一度にしか現れません。 |
| 347 | (L<http://www.unicode.org/notes/tn21>を参照してください | |
| 362 | (L<https://www.unicode.org/notes/tn21>を参照してください。) | |
| 348 | 363 | |
| 349 | 364 | =begin original |
| 350 | 365 | |
| 351 | 366 | Any character not matched by C<\d> is matched by C<\D>. |
| 352 | 367 | |
| 353 | 368 | =end original |
| 354 | 369 | |
| 355 | 370 | C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。 |
| 356 | 371 | |
| 357 | 372 | =head3 Word characters |
| 358 | 373 | |
| 359 | 374 | (単語文字) |
| 360 | 375 | |
| 361 | 376 | =begin original |
| 362 | 377 | |
| 363 | 378 | A C<\w> matches a single alphanumeric character (an alphabetic character, or a |
| 364 | 379 | decimal digit); or a connecting punctuation character, such as an |
| 365 | 380 | underscore ("_"); or a "mark" character (like some sort of accent) that |
| 366 | 381 | attaches to one of those. It does not match a whole word. To match a |
| 367 | 382 | whole word, use C<\w+>. This isn't the same thing as matching an |
| 368 | 383 | English word, but in the ASCII range it is the same as a string of |
| 369 | 384 | Perl-identifier characters. |
| 370 | 385 | |
| 371 | 386 | =end original |
| 372 | 387 | |
| 373 | 388 | C<\w> は単語全体ではなく、単一の英数字(つまり英字または数字)または |
| 374 | 389 | 下線(C<_>) のような接続句読点 |
| 375 | 390 | またはこれらの一つに付いている(ある種のアクセントのような)「マーク」文字に |
| 376 | 391 | マッチングします。 |
| 377 | 392 | これは単語全体にはマッチングしません。 |
| 378 | 393 | 単語全体にマッチングするには、C<\w+> を使ってください。 |
| 379 | 394 | これは英語の単語にマッチングするのと同じことではありませんが、 |
| 380 | 395 | ASCII の範囲では、Perl の識別子文字の文字列と同じです。 |
| 381 | 396 | |
| 382 | 397 | =over |
| 383 | 398 | |
| 384 | 399 | =item If the C</a> modifier is in effect ... |
| 385 | 400 | |
| 386 | 401 | (C</a> 修飾子が有効なら ...) |
| 387 | 402 | |
| 388 | 403 | =begin original |
| 389 | 404 | |
| 390 | 405 | C<\w> matches the 63 characters [a-zA-Z0-9_]. |
| 391 | 406 | |
| 392 | 407 | =end original |
| 393 | 408 | |
| 394 | 409 | C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。 |
| 395 | 410 | |
| 396 | 411 | =item otherwise ... |
| 397 | 412 | |
| 398 | 413 | (さもなければ ...) |
| 399 | 414 | |
| 400 | 415 | =over |
| 401 | 416 | |
| 402 | 417 | =item For code points above 255 ... |
| 403 | 418 | |
| 404 | 419 | (256 以上の符号位置では ...) |
| 405 | 420 | |
| 406 | 421 | =begin original |
| 407 | 422 | |
| 408 | 423 | C<\w> matches the same as C<\p{Word}> matches in this range. That is, |
| 409 | 424 | it matches Thai letters, Greek letters, etc. This includes connector |
| 410 | 425 | punctuation (like the underscore) which connect two words together, or |
| 411 | 426 | diacritics, such as a C<COMBINING TILDE> and the modifier letters, which |
| 412 | 427 | are generally used to add auxiliary markings to letters. |
| 413 | 428 | |
| 414 | 429 | =end original |
| 415 | 430 | |
| 416 | 431 | C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに |
| 417 | 432 | マッチングします。 |
| 418 | 433 | つまり、タイ文字、ギリシャ文字などです。 |
| 419 | 434 | これには(下線のような)二つの単語を繋ぐ接続句読点、 |
| 420 | 435 | C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために |
| 421 | 436 | 使われる修飾字のようなダイアクリティカルマークが含まれます。 |
| 422 | 437 | |
| 423 | 438 | =item For code points below 256 ... |
| 424 | 439 | |
| 425 | 440 | (255 以下の符号位置では ...) |
| 426 | 441 | |
| 427 | 442 | =over |
| 428 | 443 | |
| 429 | 444 | =item if locale rules are in effect ... |
| 430 | 445 | |
| 431 | 446 | (ロケール規則が有効なら ...) |
| 432 | 447 | |
| 433 | 448 | =begin original |
| 434 | 449 | |
| 435 | 450 | C<\w> matches the platform's native underscore character plus whatever |
| 436 | 451 | the locale considers to be alphanumeric. |
| 437 | 452 | |
| 438 | 453 | =end original |
| 439 | 454 | |
| 440 | 455 | C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と |
| 441 | 456 | 考えるものにマッチングします。 |
| 442 | 457 | |
| 443 | =item if Unicode rules are in effect ... | |
| 458 | =item if, instead, Unicode rules are in effect ... | |
| 444 | 459 | |
| 445 | (Unicode 規則が有効なら ...) | |
| 460 | (そうではなく、Unicode 規則が有効なら ...) | |
| 446 | 461 | |
| 447 | 462 | =begin original |
| 448 | 463 | |
| 449 | 464 | C<\w> matches exactly what C<\p{Word}> matches. |
| 450 | 465 | |
| 451 | 466 | =end original |
| 452 | 467 | |
| 453 | 468 | C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。 |
| 454 | 469 | |
| 455 | 470 | =item otherwise ... |
| 456 | 471 | |
| 457 | 472 | (さもなければ ...) |
| 458 | 473 | |
| 459 | 474 | =begin original |
| 460 | 475 | |
| 461 | 476 | C<\w> matches [a-zA-Z0-9_]. |
| 462 | 477 | |
| 463 | 478 | =end original |
| 464 | 479 | |
| 465 | 480 | C<\w> は [a-zA-Z0-9_] にマッチングします。 |
| 466 | 481 | |
| 467 | 482 | =back |
| 468 | 483 | |
| 469 | 484 | =back |
| 470 | 485 | |
| 471 | 486 | =back |
| 472 | 487 | |
| 473 | 488 | =begin original |
| 474 | 489 | |
| 475 | 490 | Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>. |
| 476 | 491 | |
| 477 | 492 | =end original |
| 478 | 493 | |
| 479 | 494 | どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で |
| 480 | 495 | 記述されている方法で決定されます。 |
| 481 | 496 | |
| 482 | 497 | =begin original |
| 483 | 498 | |
| 484 | 499 | There are a number of security issues with the full Unicode list of word |
| 485 | characters. See L<http://unicode.org/reports/tr36>. | |
| 500 | characters. See L<https://unicode.org/reports/tr36>. | |
| 486 | 501 | |
| 487 | 502 | =end original |
| 488 | 503 | |
| 489 | 504 | 完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。 |
| 490 | L<http://unicode.org/reports/tr36> を参照してください。 | |
| 505 | L<https://unicode.org/reports/tr36> を参照してください。 | |
| 491 | 506 | |
| 492 | 507 | =begin original |
| 493 | 508 | |
| 494 | 509 | Also, for a somewhat finer-grained set of characters that are in programming |
| 495 | 510 | language identifiers beyond the ASCII range, you may wish to instead use the |
| 496 | 511 | more customized L</Unicode Properties>, C<\p{ID_Start}>, |
| 497 | 512 | C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See |
| 498 | 513 | L<http://unicode.org/reports/tr31>. |
| 499 | 514 | |
| 500 | 515 | =end original |
| 501 | 516 | |
| 502 | 517 | また、ASCII の範囲を超えたプログラミング言語識別子のための |
| 503 | 518 | より高精度の文字集合のためには、代わりによりカスタマイズされた |
| 504 | 519 | L<Unicode 特性|/Unicode Properties>である |
| 505 | 520 | C<\p{ID_Start}>, |
| 506 | 521 | C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を |
| 507 | 522 | 使った方がよいでしょう。 |
| 508 | 523 | L<http://unicode.org/reports/tr31> を参照してください。 |
| 509 | 524 | |
| 510 | 525 | =begin original |
| 511 | 526 | |
| 512 | 527 | Any character not matched by C<\w> is matched by C<\W>. |
| 513 | 528 | |
| 514 | 529 | =end original |
| 515 | 530 | |
| 516 | 531 | C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。 |
| 517 | 532 | |
| 518 | 533 | =head3 Whitespace |
| 519 | 534 | |
| 520 | 535 | (空白) |
| 521 | 536 | |
| 522 | 537 | =begin original |
| 523 | 538 | |
| 524 | 539 | C<\s> matches any single character considered whitespace. |
| 525 | 540 | |
| 526 | 541 | =end original |
| 527 | 542 | |
| 528 | 543 | C<\s> は空白と考えられる単一の文字にマッチングします。 |
| 529 | 544 | |
| 530 | 545 | =over |
| 531 | 546 | |
| 532 | 547 | =item If the C</a> modifier is in effect ... |
| 533 | 548 | |
| 534 | 549 | (C</a> 修飾子が有効なら ...) |
| 535 | 550 | |
| 536 | 551 | =begin original |
| 537 | 552 | |
| 538 | 553 | In all Perl versions, C<\s> matches the 5 characters [\t\n\f\r ]; that |
| 539 | 554 | is, the horizontal tab, |
| 540 | 555 | the newline, the form feed, the carriage return, and the space. |
| 541 | Starting in Perl v5.18, | |
| 556 | Starting in Perl v5.18, it also matches the vertical tab, C<\cK>. | |
| 542 | 557 | See note C<[1]> below for a discussion of this. |
| 543 | 558 | |
| 544 | 559 | =end original |
| 545 | 560 | |
| 546 | 561 | 全ての Perl バージョンで、C<\s> は [\t\n\f\r ] の 5 文字にマッチングします; |
| 547 | 562 | つまり、水平タブ、改行、改頁、復帰、スペースです。 |
| 548 | Perl 5.18 から、 | |
| 563 | Perl 5.18 から、垂直タブ C<\cK> にもマッチングします。 | |
| 549 | 564 | ここでの議論については後述する C<[1]> を参照してください。 |
| 550 | 565 | |
| 551 | 566 | =item otherwise ... |
| 552 | 567 | |
| 553 | 568 | (さもなければ ...) |
| 554 | 569 | |
| 555 | 570 | =over |
| 556 | 571 | |
| 557 | 572 | =item For code points above 255 ... |
| 558 | 573 | |
| 559 | 574 | (256 以上の符号位置では ...) |
| 560 | 575 | |
| 561 | 576 | =begin original |
| 562 | 577 | |
| 563 | 578 | C<\s> matches exactly the code points above 255 shown with an "s" column |
| 564 | 579 | in the table below. |
| 565 | 580 | |
| 566 | 581 | =end original |
| 567 | 582 | |
| 568 | 583 | C<\s> は、後述する表の "s" の列で示されている、 |
| 569 | 584 | 255 を超える符号位置に正確にマッチングします。 |
| 570 | 585 | |
| 571 | 586 | =item For code points below 256 ... |
| 572 | 587 | |
| 573 | 588 | (255 以下の符号位置では ...) |
| 574 | 589 | |
| 575 | 590 | =over |
| 576 | 591 | |
| 577 | 592 | =item if locale rules are in effect ... |
| 578 | 593 | |
| 579 | 594 | (ロケール規則が有効なら ...) |
| 580 | 595 | |
| 581 | 596 | =begin original |
| 582 | 597 | |
| 583 | 598 | C<\s> matches whatever the locale considers to be whitespace. |
| 584 | 599 | |
| 585 | 600 | =end original |
| 586 | 601 | |
| 587 | 602 | C<\s> はロケールが空白だと考えるものにマッチングします。 |
| 588 | 603 | |
| 589 | =item if Unicode rules are in effect ... | |
| 604 | =item if, instead, Unicode rules are in effect ... | |
| 590 | 605 | |
| 591 | (Unicode 規則が有効なら ...) | |
| 606 | (そうではなく、Unicode 規則が有効なら ...) | |
| 592 | 607 | |
| 593 | 608 | =begin original |
| 594 | 609 | |
| 595 | 610 | C<\s> matches exactly the characters shown with an "s" column in the |
| 596 | 611 | table below. |
| 597 | 612 | |
| 598 | 613 | =end original |
| 599 | 614 | |
| 600 | 615 | C<\s> は正確に以下の表で "s" の列にある文字にマッチングします。 |
| 601 | 616 | |
| 602 | 617 | =item otherwise ... |
| 603 | 618 | |
| 604 | 619 | (さもなければ ...) |
| 605 | 620 | |
| 606 | 621 | =begin original |
| 607 | 622 | |
| 608 | C<\s> matches [\t\n\f\r | |
| 623 | C<\s> matches [\t\n\f\r ] and, starting in Perl | |
| 609 | 624 | v5.18, the vertical tab, C<\cK>. |
| 610 | 625 | (See note C<[1]> below for a discussion of this.) |
| 611 | 626 | Note that this list doesn't include the non-breaking space. |
| 612 | 627 | |
| 613 | 628 | =end original |
| 614 | 629 | |
| 615 | C<\s> は [\t\n\f\r | |
| 630 | C<\s> は [\t\n\f\r ] にマッチングし、Perl v5.18 から、 | |
| 616 | 631 | 垂直タブ C<\cK> にもマッチングします。 |
| 617 | 632 | (これの議論については後述する C<[1]> を参照してください。) |
| 618 | 633 | この一覧にはノーブレークスペースが含まれていないことに注意してください。 |
| 619 | 634 | |
| 620 | 635 | =back |
| 621 | 636 | |
| 622 | 637 | =back |
| 623 | 638 | |
| 624 | 639 | =back |
| 625 | 640 | |
| 626 | 641 | =begin original |
| 627 | 642 | |
| 628 | 643 | Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>. |
| 629 | 644 | |
| 630 | 645 | =end original |
| 631 | 646 | |
| 632 | 647 | どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で |
| 633 | 648 | 記述されている方法で決定されます。 |
| 634 | 649 | |
| 635 | 650 | =begin original |
| 636 | 651 | |
| 637 | 652 | Any character not matched by C<\s> is matched by C<\S>. |
| 638 | 653 | |
| 639 | 654 | =end original |
| 640 | 655 | |
| 641 | 656 | C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。 |
| 642 | 657 | |
| 643 | 658 | =begin original |
| 644 | 659 | |
| 645 | 660 | C<\h> matches any character considered horizontal whitespace; |
| 646 | 661 | this includes the platform's space and tab characters and several others |
| 647 | 662 | listed in the table below. C<\H> matches any character |
| 648 | 663 | not considered horizontal whitespace. They use the platform's native |
| 649 | 664 | character set, and do not consider any locale that may otherwise be in |
| 650 | 665 | use. |
| 651 | 666 | |
| 652 | 667 | =end original |
| 653 | 668 | |
| 654 | 669 | C<\h> は水平空白と考えられる任意の文字にマッチングします; これは |
| 655 | 670 | プラットフォームのスペースとタブ文字および以下の表に上げられている |
| 656 | 671 | いくつかのその他の文字です。 |
| 657 | 672 | C<\H> は水平空白と考えられない文字にマッチングします。 |
| 658 | 673 | これらはプラットフォームのネイティブな文字集合を使い、 |
| 659 | 674 | 他の場所では有効なロケールを考慮しません。 |
| 660 | 675 | |
| 661 | 676 | =begin original |
| 662 | 677 | |
| 663 | 678 | C<\v> matches any character considered vertical whitespace; |
| 664 | 679 | this includes the platform's carriage return and line feed characters (newline) |
| 665 | 680 | plus several other characters, all listed in the table below. |
| 666 | 681 | C<\V> matches any character not considered vertical whitespace. |
| 667 | 682 | They use the platform's native character set, and do not consider any |
| 668 | 683 | locale that may otherwise be in use. |
| 669 | 684 | |
| 670 | 685 | =end original |
| 671 | 686 | |
| 672 | 687 | C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは |
| 673 | 688 | プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です; |
| 674 | 689 | 全ては以下の表に挙げられています。 |
| 675 | 690 | C<\V> は垂直空白と考えられない任意の文字にマッチングします。 |
| 676 | 691 | これらはプラットフォームのネイティブな文字集合を使い、 |
| 677 | 692 | 他の場所では有効なロケールを考慮しません。 |
| 678 | 693 | |
| 679 | 694 | =begin original |
| 680 | 695 | |
| 681 | 696 | C<\R> matches anything that can be considered a newline under Unicode |
| 682 | rules. It | |
| 697 | rules. It can match a multi-character sequence. It cannot be used inside | |
| 683 | ||
| 698 | a bracketed character class; use C<\v> instead (vertical whitespace). | |
| 684 | ||
| 699 | It uses the platform's | |
| 685 | 700 | native character set, and does not consider any locale that may |
| 686 | 701 | otherwise be in use. |
| 687 | 702 | Details are discussed in L<perlrebackslash>. |
| 688 | 703 | |
| 689 | 704 | =end original |
| 690 | 705 | |
| 691 | 706 | C<\R> は Unicode の規則で改行と考えられるものにマッチングします。 |
| 692 | 複数文字の並びにマッチングすることもあ | |
| 707 | 複数文字の並びにマッチングすることもあります。 | |
| 693 | 文字クラスではありません。 | |
| 694 | 708 | 従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を |
| 695 | 709 | 使ってください。 |
| 696 | 710 | これらはプラットフォームのネイティブな文字集合を使い、 |
| 697 | 711 | 他の場所では有効なロケールを考慮しません。 |
| 698 | 712 | 詳細は L<perlrebackslash> で議論しています。 |
| 699 | 713 | |
| 700 | 714 | =begin original |
| 701 | 715 | |
| 702 | 716 | Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match |
| 703 | 717 | the same characters, without regard to other factors, such as the active |
| 704 | 718 | locale or whether the source string is in UTF-8 format. |
| 705 | 719 | |
| 706 | 720 | =end original |
| 707 | 721 | |
| 708 | 722 | C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の |
| 709 | 723 | ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず |
| 710 | 724 | 同じ文字にマッチングします。 |
| 711 | 725 | |
| 712 | 726 | =begin original |
| 713 | 727 | |
| 714 | 728 | One might think that C<\s> is equivalent to C<[\h\v]>. This is indeed true |
| 715 | 729 | starting in Perl v5.18, but prior to that, the sole difference was that the |
| 716 | 730 | vertical tab (C<"\cK">) was not matched by C<\s>. |
| 717 | 731 | |
| 718 | 732 | =end original |
| 719 | 733 | |
| 720 | 734 | C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。 |
| 721 | 735 | Perl 5.18 からはもちろん正しいです; しかしそれより前では、 |
| 722 | 736 | 唯一の違いは、垂直タブ (C<"\xcK">) は C<\s> にマッチングしないということです。 |
| 723 | 737 | |
| 724 | 738 | =begin original |
| 725 | 739 | |
| 726 | 740 | The following table is a complete listing of characters matched by |
| 727 | C<\s>, C<\h> and C<\v> as of Unicode | |
| 741 | C<\s>, C<\h> and C<\v> as of Unicode 14.0. | |
| 728 | 742 | |
| 729 | 743 | =end original |
| 730 | 744 | |
| 731 | 以下の表は Unicode | |
| 745 | 以下の表は Unicode 14.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の | |
| 732 | 746 | 完全な一覧です。 |
| 733 | 747 | |
| 734 | 748 | =begin original |
| 735 | 749 | |
| 736 | 750 | The first column gives the Unicode code point of the character (in hex format), |
| 737 | 751 | the second column gives the (Unicode) name. The third column indicates |
| 738 | 752 | by which class(es) the character is matched (assuming no locale is in |
| 739 | 753 | effect that changes the C<\s> matching). |
| 740 | 754 | |
| 741 | 755 | =end original |
| 742 | 756 | |
| 743 | 757 | 最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の) |
| 744 | 758 | 名前です。 |
| 745 | 759 | 3 番目の列はどのクラスにマッチングするかを示しています |
| 746 | 760 | (C<\s> のマッチングを変更するようなロケールが |
| 747 | 761 | 有効でないことを仮定しています)。 |
| 748 | 762 | |
| 749 | 763 | 0x0009 CHARACTER TABULATION h s |
| 750 | 764 | 0x000a LINE FEED (LF) vs |
| 751 | 765 | 0x000b LINE TABULATION vs [1] |
| 752 | 766 | 0x000c FORM FEED (FF) vs |
| 753 | 767 | 0x000d CARRIAGE RETURN (CR) vs |
| 754 | 768 | 0x0020 SPACE h s |
| 755 | 769 | 0x0085 NEXT LINE (NEL) vs [2] |
| 756 | 770 | 0x00a0 NO-BREAK SPACE h s [2] |
| 757 | 771 | 0x1680 OGHAM SPACE MARK h s |
| 758 | 0x180e MONGOLIAN VOWEL SEPARATOR h s | |
| 759 | 772 | 0x2000 EN QUAD h s |
| 760 | 773 | 0x2001 EM QUAD h s |
| 761 | 774 | 0x2002 EN SPACE h s |
| 762 | 775 | 0x2003 EM SPACE h s |
| 763 | 776 | 0x2004 THREE-PER-EM SPACE h s |
| 764 | 777 | 0x2005 FOUR-PER-EM SPACE h s |
| 765 | 778 | 0x2006 SIX-PER-EM SPACE h s |
| 766 | 779 | 0x2007 FIGURE SPACE h s |
| 767 | 780 | 0x2008 PUNCTUATION SPACE h s |
| 768 | 781 | 0x2009 THIN SPACE h s |
| 769 | 782 | 0x200a HAIR SPACE h s |
| 770 | 783 | 0x2028 LINE SEPARATOR vs |
| 771 | 784 | 0x2029 PARAGRAPH SEPARATOR vs |
| 772 | 785 | 0x202f NARROW NO-BREAK SPACE h s |
| 773 | 786 | 0x205f MEDIUM MATHEMATICAL SPACE h s |
| 774 | 787 | 0x3000 IDEOGRAPHIC SPACE h s |
| 775 | 788 | |
| 776 | 789 | =over 4 |
| 777 | 790 | |
| 778 | 791 | =item [1] |
| 779 | 792 | |
| 780 | 793 | =begin original |
| 781 | 794 | |
| 782 | Prior to Perl v5.18, C<\s> did not match the vertical tab. | |
| 795 | Prior to Perl v5.18, C<\s> did not match the vertical tab. | |
| 783 | ||
| 796 | C<[^\S\cK]> (obscurely) matches what C<\s> traditionally did. | |
| 784 | in v5.20 or v5.22 if experience indicates that it breaks too much | |
| 785 | existing code. If this change adversely affects you, send email to | |
| 786 | C<perlbug@perl.org>; if it affects you positively, email | |
| 787 | C<perlthanks@perl.org>. In the meantime, C<[^\S\cK]> (obscurely) | |
| 788 | matches what C<\s> traditionally did. | |
| 789 | 797 | |
| 790 | 798 | =end original |
| 791 | 799 | |
| 792 | 800 | Perl v5.18 より前では、C<\s> は垂直タブにマッチングしませんでした。 |
| 793 | ||
| 801 | C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的に | |
| 794 | これがあまりに多くの既存のコードを壊すことが分かった場合は、 | |
| 795 | v5.20 や v5.22 で元に戻すかもしれません。 | |
| 796 | この変更があなたに不利に働いた場合は、 | |
| 797 | C<perlbug@perl.org> にメールしてください; あなたに有利に働いた場合は、 | |
| 798 | C<perlthanks@perl.org> にメールしてください。 | |
| 799 | それまでの間は、C<[^\S\cK]> は(ひっそりと)C<\s> が伝統的に | |
| 800 | 802 | マッチングしていたものにマッチングします。 |
| 801 | 803 | |
| 802 | 804 | =item [2] |
| 803 | 805 | |
| 804 | 806 | =begin original |
| 805 | 807 | |
| 806 | 808 | NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending |
| 807 | 809 | on the rules in effect. See |
| 808 | 810 | L<the beginning of this section|/Whitespace>. |
| 809 | 811 | |
| 810 | 812 | =end original |
| 811 | 813 | |
| 812 | 814 | NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に |
| 813 | 815 | マッチングしたりマッチングしなかったりします。 |
| 814 | 816 | L<the beginning of this section|/Whitespace> を参照してください。 |
| 815 | 817 | |
| 816 | 818 | =back |
| 817 | 819 | |
| 818 | 820 | =head3 Unicode Properties |
| 819 | 821 | |
| 820 | 822 | (Unicode 特性) |
| 821 | 823 | |
| 822 | 824 | =begin original |
| 823 | 825 | |
| 824 | 826 | C<\pP> and C<\p{Prop}> are character classes to match characters that fit given |
| 825 | 827 | Unicode properties. One letter property names can be used in the C<\pP> form, |
| 826 | 828 | with the property name following the C<\p>, otherwise, braces are required. |
| 827 | 829 | When using braces, there is a single form, which is just the property name |
| 828 | 830 | enclosed in the braces, and a compound form which looks like C<\p{name=value}>, |
| 829 | 831 | which means to match if the property "name" for the character has that particular |
| 830 | 832 | "value". |
| 831 | 833 | For instance, a match for a number can be written as C</\pN/> or as |
| 832 | 834 | C</\p{Number}/>, or as C</\p{Number=True}/>. |
| 833 | 835 | Lowercase letters are matched by the property I<Lowercase_Letter> which |
| 834 | 836 | has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or |
| 835 | 837 | C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/> |
| 836 | 838 | (the underscores are optional). |
| 837 | 839 | C</\pLl/> is valid, but means something different. |
| 838 | 840 | It matches a two character string: a letter (Unicode property C<\pL>), |
| 839 | 841 | followed by a lowercase C<l>. |
| 840 | 842 | |
| 841 | 843 | =end original |
| 842 | 844 | |
| 843 | 845 | C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に |
| 844 | 846 | マッチングする文字クラスです。 |
| 845 | 847 | 一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ |
| 846 | 848 | 中かっこが必要です。 |
| 847 | 849 | 中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、 |
| 848 | 850 | C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を |
| 849 | 851 | 持つものにマッチングすることになる複合形式があります。 |
| 850 | 852 | 例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または |
| 851 | 853 | C</\p{Number=True}/> と書けます。 |
| 852 | 854 | 小文字は I<LowercaseLetter> 特性にマッチングします; これには |
| 853 | 855 | I<Ll> と言う短縮形式があります。 |
| 854 | 856 | 中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または |
| 855 | 857 | C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。 |
| 856 | 858 | C</\pLl/> も妥当ですが、違う意味になります。 |
| 857 | 859 | これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて |
| 858 | 860 | 小文字の C<l> です。 |
| 859 | 861 | |
| 860 | 862 | =begin original |
| 861 | 863 | |
| 862 | ||
| 864 | What a Unicode property matches is never subject to locale rules, and | |
| 863 | ||
| 865 | if locale rules are not otherwise in effect, the use of a Unicode | |
| 864 | rules | |
| 866 | property will force the regular expression into using Unicode rules, if | |
| 867 | it isn't already. | |
| 865 | 868 | |
| 866 | 869 | =end original |
| 867 | 870 | |
| 871 | Unicode 特性が何にマッチングするかは決してロケールの規則に影響されず、 | |
| 868 | 872 | ロケール規則が有効でない場合、Unicode 特性を使うと |
| 869 | 873 | 正規表現に (まだそうでなければ) Unicode 規則を使うように強制します。 |
| 870 | 874 | |
| 871 | 875 | =begin original |
| 872 | 876 | |
| 873 | 877 | Note that almost all properties are immune to case-insensitive matching. |
| 874 | 878 | That is, adding a C</i> regular expression modifier does not change what |
| 875 | they match. | |
| 879 | they match. But there are two sets that are affected. The first set is | |
| 876 | 880 | C<Uppercase_Letter>, |
| 877 | 881 | C<Lowercase_Letter>, |
| 878 | 882 | and C<Titlecase_Letter>, |
| 879 | 883 | all of which match C<Cased_Letter> under C</i> matching. |
| 880 | 884 | The second set is |
| 881 | 885 | C<Uppercase>, |
| 882 | 886 | C<Lowercase>, |
| 883 | 887 | and C<Titlecase>, |
| 884 | 888 | all of which match C<Cased> under C</i> matching. |
| 885 | 889 | (The difference between these sets is that some things, such as Roman |
| 886 | 890 | numerals, come in both upper and lower case, so they are C<Cased>, but |
| 887 | 891 | aren't considered to be letters, so they aren't C<Cased_Letter>s. They're |
| 888 | 892 | actually C<Letter_Number>s.) |
| 889 | 893 | This set also includes its subsets C<PosixUpper> and C<PosixLower>, both |
| 890 | 894 | of which under C</i> match C<PosixAlpha>. |
| 891 | 895 | |
| 892 | 896 | =end original |
| 893 | 897 | |
| 894 | 898 | ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに |
| 895 | 899 | 注意してください。 |
| 896 | 900 | つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を |
| 897 | 901 | 与えないということです。 |
| 898 | 影響を与える二つの集合があります。 | |
| 902 | しかし、影響を与える二つの集合があります。 | |
| 899 | 903 | 一つ目の集合は |
| 900 | 904 | C<Uppercase_Letter>, |
| 901 | 905 | C<Lowercase_Letter>, |
| 902 | 906 | C<Titlecase_Letter> で、全て C</i> マッチングの下で |
| 903 | 907 | C<Cased_Letter> にマッチングします。 |
| 904 | 908 | 二つ目の集合は |
| 905 | 909 | C<Uppercase>, |
| 906 | 910 | C<Lowercase>, |
| 907 | 911 | C<Titlecase> で、全てC</i> マッチングの下で |
| 908 | 912 | C<Cased> にマッチングします。 |
| 909 | 913 | (これらの集合の違いは、ローマ数字のような一部のものは、 |
| 910 | 914 | 大文字と小文字があるので C<Cased> ですが、 |
| 911 | 915 | 文字とは扱われないので C<Cased_Letter> ではありません。 |
| 912 | 916 | これらは実際には C<Letter_Number> です。) |
| 913 | 917 | この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます; |
| 914 | 918 | これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。 |
| 915 | 919 | |
| 916 | 920 | =begin original |
| 917 | 921 | |
| 918 | 922 | For more details on Unicode properties, see L<perlunicode/Unicode |
| 919 | 923 | Character Properties>; for a |
| 920 | 924 | complete list of possible properties, see |
| 921 | 925 | L<perluniprops/Properties accessible through \p{} and \P{}>, |
| 922 | 926 | which notes all forms that have C</i> differences. |
| 923 | 927 | It is also possible to define your own properties. This is discussed in |
| 924 | 928 | L<perlunicode/User-Defined Character Properties>. |
| 925 | 929 | |
| 926 | 930 | =end original |
| 927 | 931 | |
| 928 | 932 | Unicode 特性に関するさらなる詳細については、 |
| 929 | 933 | L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な |
| 930 | 934 | 一覧については、C</i> に違いのある全ての形式について記されている |
| 931 | 935 | L<perluniprops/Properties accessible through \p{} and \P{}> を参照して |
| 932 | 936 | ください。 |
| 933 | 937 | 独自の特性を定義することも可能です。 |
| 934 | 938 | これは L<perlunicode/User-Defined Character Properties> で |
| 935 | 939 | 議論されています。 |
| 936 | 940 | |
| 937 | 941 | =begin original |
| 938 | 942 | |
| 939 | 943 | Unicode properties are defined (surprise!) only on Unicode code points. |
| 940 | ||
| 944 | Starting in v5.20, when matching against C<\p> and C<\P>, Perl treats | |
| 941 | (those above the legal Unicode maximum of | |
| 945 | non-Unicode code points (those above the legal Unicode maximum of | |
| 942 | ||
| 946 | 0x10FFFF) as if they were typical unassigned Unicode code points. | |
| 943 | 947 | |
| 944 | 948 | =end original |
| 945 | 949 | |
| 946 | 950 | Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ |
| 947 | 951 | 定義されています。 |
| 948 | ||
| 952 | v5.20 から、C<\p> と C<\P> に対してマッチングするとき、 | |
| 949 | ||
| 953 | Perl は | |
| 950 | ||
| 954 | 非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) を、 | |
| 955 | 典型的な未割り当て Unicode 符号位置であるかのように扱います。 | |
| 951 | 956 | |
| 952 | ||
| 957 | =begin original | |
| 953 | chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails! | |
| 954 | 958 | |
| 959 | Prior to v5.20, Perl raised a warning and made all matches fail on | |
| 960 | non-Unicode code points. This could be somewhat surprising: | |
| 961 | ||
| 962 | =end original | |
| 963 | ||
| 964 | v5.20 より前では、非 Unicode 符号位置に対しては全てのマッチングは失敗して、 | |
| 965 | Perl は警告を出していました。 | |
| 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 | ||
| 955 | 972 | =begin original |
| 956 | 973 | |
| 957 | Even though these two matches might be thought of as complements, t | |
| 974 | Even though these two matches might be thought of as complements, until | |
| 958 | ||
| 975 | v5.20 they were so only on Unicode code points. | |
| 959 | 976 | |
| 960 | 977 | =end original |
| 961 | 978 | |
| 962 | 979 | これら二つのマッチングは補集合と考えるかもしれませんが、 |
| 963 | これらは Unicode 符号位置だけで | |
| 980 | v5.20 まで、これらは Unicode 符号位置だけでした。 | |
| 964 | 981 | |
| 982 | =begin original | |
| 983 | ||
| 984 | Starting in perl v5.30, wildcards are allowed in Unicode property | |
| 985 | values. See L<perlunicode/Wildcards in Property Values>. | |
| 986 | ||
| 987 | =end original | |
| 988 | ||
| 989 | perl v5.30 から、Unicode 特性にワイルドカードを使えます。 | |
| 990 | L<perlunicode/Wildcards in Property Values> を参照してください。 | |
| 991 | ||
| 965 | 992 | =head4 Examples |
| 966 | 993 | |
| 967 | 994 | (例) |
| 968 | 995 | |
| 969 | 996 | =begin original |
| 970 | 997 | |
| 971 | 998 | "a" =~ /\w/ # Match, "a" is a 'word' character. |
| 972 | 999 | "7" =~ /\w/ # Match, "7" is a 'word' character as well. |
| 973 | 1000 | "a" =~ /\d/ # No match, "a" isn't a digit. |
| 974 | 1001 | "7" =~ /\d/ # Match, "7" is a digit. |
| 975 | 1002 | " " =~ /\s/ # Match, a space is whitespace. |
| 976 | 1003 | "a" =~ /\D/ # Match, "a" is a non-digit. |
| 977 | 1004 | "7" =~ /\D/ # No match, "7" is not a non-digit. |
| 978 | 1005 | " " =~ /\S/ # No match, a space is not non-whitespace. |
| 979 | 1006 | |
| 980 | 1007 | =end original |
| 981 | 1008 | |
| 982 | 1009 | "a" =~ /\w/ # マッチング; "a" は「単語」文字。 |
| 983 | 1010 | "7" =~ /\w/ # マッチング; "7" も「単語」文字。 |
| 984 | 1011 | "a" =~ /\d/ # マッチングしない; "a" は数字ではない。 |
| 985 | 1012 | "7" =~ /\d/ # マッチング; "7" は数字。 |
| 986 | 1013 | " " =~ /\s/ # マッチング; スペースは空白。 |
| 987 | 1014 | "a" =~ /\D/ # マッチング; "a" は非数字。 |
| 988 | 1015 | "7" =~ /\D/ # マッチングしない; "7" は非数字ではない。 |
| 989 | 1016 | " " =~ /\S/ # マッチングしない; スペースは非空白ではない。 |
| 990 | 1017 | |
| 991 | 1018 | =begin original |
| 992 | 1019 | |
| 993 | 1020 | " " =~ /\h/ # Match, space is horizontal whitespace. |
| 994 | 1021 | " " =~ /\v/ # No match, space is not vertical whitespace. |
| 995 | 1022 | "\r" =~ /\v/ # Match, a return is vertical whitespace. |
| 996 | 1023 | |
| 997 | 1024 | =end original |
| 998 | 1025 | |
| 999 | 1026 | " " =~ /\h/ # マッチング; スペースは水平空白。 |
| 1000 | 1027 | " " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。 |
| 1001 | 1028 | "\r" =~ /\v/ # マッチング; 復帰は垂直空白。 |
| 1002 | 1029 | |
| 1003 | 1030 | =begin original |
| 1004 | 1031 | |
| 1005 | 1032 | "a" =~ /\pL/ # Match, "a" is a letter. |
| 1006 | 1033 | "a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters. |
| 1007 | 1034 | |
| 1008 | 1035 | =end original |
| 1009 | 1036 | |
| 1010 | 1037 | "a" =~ /\pL/ # マッチング; "a" は英字。 |
| 1011 | 1038 | "a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。 |
| 1012 | 1039 | |
| 1013 | 1040 | =begin original |
| 1014 | 1041 | |
| 1015 | 1042 | "\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character |
| 1016 | 1043 | # 'THAI CHARACTER SO SO', and that's in |
| 1017 | 1044 | # Thai Unicode class. |
| 1018 | 1045 | "a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character. |
| 1019 | 1046 | |
| 1020 | 1047 | =end original |
| 1021 | 1048 | |
| 1022 | 1049 | "\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字 |
| 1023 | 1050 | # 'THAI CHARACTER SO SO' で、これは |
| 1024 | 1051 | # Thai Unicode クラスにある。 |
| 1025 | 1052 | "a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。 |
| 1026 | 1053 | |
| 1027 | 1054 | =begin original |
| 1028 | 1055 | |
| 1029 | 1056 | It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not |
| 1030 | 1057 | complete numbers or words. To match a number (that consists of digits), |
| 1031 | 1058 | use C<\d+>; to match a word, use C<\w+>. But be aware of the security |
| 1032 | 1059 | considerations in doing so, as mentioned above. |
| 1033 | 1060 | |
| 1034 | 1061 | =end original |
| 1035 | 1062 | |
| 1036 | 1063 | C<\d>, C<\w> などは数値や単語全体ではなく、1 文字にマッチングすることは |
| 1037 | 1064 | 強調する価値があります。 |
| 1038 | 1065 | (数字で構成される) 数値 にマッチングするには C<\d+> を使います; |
| 1039 | 1066 | 単語にマッチングするには C<\w+> を使います。 |
| 1040 | 1067 | しかし前述したように、そうする場合のセキュリティ問題について |
| 1041 | 1068 | 注意してください。 |
| 1042 | 1069 | |
| 1043 | 1070 | =head2 Bracketed Character Classes |
| 1044 | 1071 | |
| 1045 | 1072 | (かっこ付き文字クラス) |
| 1046 | 1073 | |
| 1047 | 1074 | =begin original |
| 1048 | 1075 | |
| 1049 | 1076 | The third form of character class you can use in Perl regular expressions |
| 1050 | 1077 | is the bracketed character class. In its simplest form, it lists the characters |
| 1051 | 1078 | that may be matched, surrounded by square brackets, like this: C<[aeiou]>. |
| 1052 | 1079 | This matches one of C<a>, C<e>, C<i>, C<o> or C<u>. Like the other |
| 1053 | 1080 | character classes, exactly one character is matched.* To match |
| 1054 | 1081 | a longer string consisting of characters mentioned in the character |
| 1055 | 1082 | class, follow the character class with a L<quantifier|perlre/Quantifiers>. For |
| 1056 | 1083 | instance, C<[aeiou]+> matches one or more lowercase English vowels. |
| 1057 | 1084 | |
| 1058 | 1085 | =end original |
| 1059 | 1086 | |
| 1060 | 1087 | Perl 正規表現で使える文字クラスの第 3 の形式は大かっこ文字クラスです。 |
| 1061 | 1088 | もっとも単純な形式では、以下のように大かっこの中にマッチングする文字を |
| 1062 | 1089 | リストします: C<[aeiou]>. |
| 1063 | 1090 | これは C<a>, C<e>, C<i>, C<o>, C<u> のどれかにマッチングします。 |
| 1064 | 1091 | 他の文字クラスと同様、正確に一つの文字にマッチングします。 |
| 1065 | 1092 | 文字クラスで言及した文字で構成されるより長い文字列にマッチングするには、 |
| 1066 | 1093 | 文字クラスに L<量指定子|perlre/Quantifiers> を付けます。 |
| 1067 | 1094 | 例えば、C<[aeiou]+> は一つまたはそれ以上の小文字英語母音に |
| 1068 | 1095 | マッチングします。 |
| 1069 | 1096 | |
| 1070 | 1097 | =begin original |
| 1071 | 1098 | |
| 1072 | 1099 | Repeating a character in a character class has no |
| 1073 | 1100 | effect; it's considered to be in the set only once. |
| 1074 | 1101 | |
| 1075 | 1102 | =end original |
| 1076 | 1103 | |
| 1077 | 1104 | 文字クラスの中で文字を繰り返しても効果はありません; 一度だけ現れたものと |
| 1078 | 1105 | 考えられます。 |
| 1079 | 1106 | |
| 1080 | 1107 | =begin original |
| 1081 | 1108 | |
| 1082 | 1109 | Examples: |
| 1083 | 1110 | |
| 1084 | 1111 | =end original |
| 1085 | 1112 | |
| 1086 | 1113 | 例: |
| 1087 | 1114 | |
| 1088 | 1115 | =begin original |
| 1089 | 1116 | |
| 1090 | 1117 | "e" =~ /[aeiou]/ # Match, as "e" is listed in the class. |
| 1091 | 1118 | "p" =~ /[aeiou]/ # No match, "p" is not listed in the class. |
| 1092 | 1119 | "ae" =~ /^[aeiou]$/ # No match, a character class only matches |
| 1093 | 1120 | # a single character. |
| 1094 | 1121 | "ae" =~ /^[aeiou]+$/ # Match, due to the quantifier. |
| 1095 | 1122 | |
| 1096 | 1123 | =end original |
| 1097 | 1124 | |
| 1098 | 1125 | "e" =~ /[aeiou]/ # マッチング; "e" はクラスにある。 |
| 1099 | 1126 | "p" =~ /[aeiou]/ # マッチングしない; "p" はクラスにない。 |
| 1100 | 1127 | "ae" =~ /^[aeiou]$/ # マッチングしない; 一つの文字クラスは |
| 1101 | 1128 | # 一文字だけにマッチングする。 |
| 1102 | 1129 | "ae" =~ /^[aeiou]+$/ # マッチング; 量指定子により。 |
| 1103 | 1130 | |
| 1104 | 1131 | ------- |
| 1105 | 1132 | |
| 1106 | 1133 | =begin original |
| 1107 | 1134 | |
| 1108 | * There | |
| 1135 | * There are two exceptions to a bracketed character class matching a | |
| 1109 | single character only. | |
| 1136 | single character only. Each requires special handling by Perl to make | |
| 1110 | ||
| 1137 | things work: | |
| 1111 | class matches a | |
| 1112 | multiple-character sequence caselessly under Unicode rules, the class | |
| 1113 | (when not L<inverted|/Negation>) will also match that sequence. For | |
| 1114 | example, Unicode says that the letter C<LATIN SMALL LETTER SHARP S> | |
| 1115 | should match the sequence C<ss> under C</i> rules. Thus, | |
| 1116 | 1138 | |
| 1117 | 1139 | =end original |
| 1118 | 1140 | |
| 1119 | 1141 | * 大かっこ文字クラスは単一の文字にのみマッチングするということには |
| 1120 | ||
| 1142 | 二つの例外があります。 | |
| 1143 | それぞれは Perl がうまく動くために特別な扱いが必要です: | |
| 1144 | ||
| 1145 | =over | |
| 1146 | ||
| 1147 | =item * | |
| 1148 | ||
| 1149 | =begin original | |
| 1150 | ||
| 1151 | When the class is to match caselessly under C</i> matching rules, and a | |
| 1152 | character that is explicitly mentioned inside the class matches a | |
| 1153 | multiple-character sequence caselessly under Unicode rules, the class | |
| 1154 | will also match that sequence. For example, Unicode says that the | |
| 1155 | letter C<LATIN SMALL LETTER SHARP S> should match the sequence C<ss> | |
| 1156 | under C</i> rules. Thus, | |
| 1157 | ||
| 1158 | =end original | |
| 1159 | ||
| 1121 | 1160 | クラスが C</i> マッチング規則の下で大文字小文字を無視したマッチングを |
| 1122 | 1161 | して、クラスの中で明示的に記述された文字が Unicode の規則の下で複数文字並びに |
| 1123 | 1162 | 大文字小文字を無視してマッチングするとき、 |
| 1124 | そのクラス | |
| 1163 | そのクラスはその並びにもマッチングします。 | |
| 1125 | 1164 | 例えば、Unicode は文字 C<LATIN SMALL LETTER SHARP S> は C</i> 規則の下では |
| 1126 | 1165 | 並び C<ss> にマッチングするとしています。 |
| 1127 | 1166 | 従って: |
| 1128 | 1167 | |
| 1129 | 1168 | 'ss' =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i # Matches |
| 1130 | 1169 | 'ss' =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i # Matches |
| 1131 | 1170 | |
| 1132 | 1171 | =begin original |
| 1133 | 1172 | |
| 1134 | For this to happen, the c | |
| 1173 | For this to happen, the class must not be inverted (see L</Negation>) | |
| 1135 | ||
| 1174 | and the character must be explicitly specified, and not be part of a | |
| 1136 | ||
| 1175 | multi-character range (not even as one of its endpoints). (L</Character | |
| 1176 | Ranges> will be explained shortly.) Therefore, | |
| 1137 | 1177 | |
| 1138 | 1178 | =end original |
| 1139 | 1179 | |
| 1140 | これが起きるためには、 | |
| 1180 | これが起きるためには、 | |
| 1181 | そのクラスは否定 (L</Negation> 参照) ではなく、 | |
| 1182 | その文字は明示的に指定され、複数文字範囲の一部 | |
| 1141 | 1183 | (たとえその端でも)でない必要があります。 |
| 1142 | 1184 | (L</Character Ranges> は短く説明されています。) |
| 1143 | 1185 | 従って: |
| 1144 | 1186 | |
| 1145 | 'ss' =~ /\A[\0-\x{ff}]\z/i | |
| 1187 | 'ss' =~ /\A[\0-\x{ff}]\z/ui # Doesn't match | |
| 1146 | 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/i | |
| 1188 | 'ss' =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui # No match | |
| 1147 | 'ss' =~ /\A[\xDF-\xDF]\z/i | |
| 1189 | 'ss' =~ /\A[\xDF-\xDF]\z/ui # Matches on ASCII platforms, since | |
| 1148 | # is LATIN SMALL LETTER SHARP S, | |
| 1190 | # \xDF is LATIN SMALL LETTER SHARP S, | |
| 1149 | # range is just a single | |
| 1191 | # and the range is just a single | |
| 1192 | # element | |
| 1150 | 1193 | |
| 1151 | 1194 | =begin original |
| 1152 | 1195 | |
| 1153 | 1196 | Note that it isn't a good idea to specify these types of ranges anyway. |
| 1154 | 1197 | |
| 1155 | 1198 | =end original |
| 1156 | 1199 | |
| 1157 | 1200 | どちらにしろこれらの種類の範囲を指定するのは良い考えではありません。 |
| 1158 | 1201 | |
| 1202 | =item * | |
| 1203 | ||
| 1204 | =begin original | |
| 1205 | ||
| 1206 | Some names known to C<\N{...}> refer to a sequence of multiple characters, | |
| 1207 | instead of the usual single character. When one of these is included in | |
| 1208 | the class, the entire sequence is matched. For example, | |
| 1209 | ||
| 1210 | =end original | |
| 1211 | ||
| 1212 | Some names known to | |
| 1213 | C<\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 | ||
| 1223 | matches, because C<\N{TAMIL SYLLABLE KAU}> is a named sequence | |
| 1224 | consisting of the two characters matched against. Like the other | |
| 1225 | instance where a bracketed class can match multiple characters, and for | |
| 1226 | similar reasons, the class must not be inverted, and the named sequence | |
| 1227 | may not appear in a range, even one where it is both endpoints. If | |
| 1228 | these happen, it is a fatal error if the character class is within the | |
| 1229 | scope of L<C<use re 'strict>|re/'strict' mode>, or within an extended | |
| 1230 | L<C<(?[...])>|/Extended Bracketed Character Classes> class; otherwise | |
| 1231 | only the first code point is used (with a C<regexp>-type warning | |
| 1232 | raised). | |
| 1233 | ||
| 1234 | =end original | |
| 1235 | ||
| 1236 | これはマッチングします; なぜなら C<\N{TAMIL SYLLABLE KAU}> は | |
| 1237 | マッチングする二つの文字からなる名前付き並びだからです。 | |
| 1238 | 大かっこクラスが複数の文字にマッチングするその他の例と同じように、 | |
| 1239 | そして同様の理由で、クラスは否定できず、 | |
| 1240 | たとえ両端の間であっても名前付き並びは範囲の中には現れません。 | |
| 1241 | これらが起きたとき、文字クラスが | |
| 1242 | L<C<use re 'strict>|re/'strict' mode> のスコープ内か、 | |
| 1243 | 拡張された L<C<(?[...])>|/Extended Bracketed Character Classes> クラスの | |
| 1244 | 中の場合には致命的エラーになります; | |
| 1245 | さもなければ、最初の符号位置のみが使われます | |
| 1246 | (そして C<regexp> 系の警告が発生します)。 | |
| 1247 | ||
| 1248 | =back | |
| 1249 | ||
| 1159 | 1250 | =head3 Special Characters Inside a Bracketed Character Class |
| 1160 | 1251 | |
| 1161 | 1252 | (かっこ付き文字クラスの中の特殊文字) |
| 1162 | 1253 | |
| 1163 | 1254 | =begin original |
| 1164 | 1255 | |
| 1165 | 1256 | Most characters that are meta characters in regular expressions (that |
| 1166 | 1257 | is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose |
| 1167 | 1258 | their special meaning and can be used inside a character class without |
| 1168 | 1259 | the need to escape them. For instance, C<[()]> matches either an opening |
| 1169 | 1260 | parenthesis, or a closing parenthesis, and the parens inside the character |
| 1170 | class don't group or capture. | |
| 1261 | class don't group or capture. Be aware that, unless the pattern is | |
| 1262 | evaluated in single-quotish context, variable interpolation will take | |
| 1263 | place before the bracketed class is parsed: | |
| 1171 | 1264 | |
| 1172 | 1265 | =end original |
| 1173 | 1266 | |
| 1174 | 1267 | 正規表現内でメタ文字(つまり、C<.>, C<*>, C<(> のように特別な意味を持つ |
| 1175 | 1268 | 文字)となるほとんどの文字は文字クラス内ではエスケープしなくても特別な意味を |
| 1176 | 1269 | 失うので、エスケープする必要はありません。 |
| 1177 | 1270 | 例えば、C<[()]> は開きかっこまたは閉じかっこにマッチングし、文字クラスの中の |
| 1178 | 1271 | かっこはグループや捕捉にはなりません。 |
| 1272 | パターンがシングルクォート風コンテキストの中で評価されない限り、 | |
| 1273 | 変数展開は大かっこクラスがパースされる前に行われることに注意してください: | |
| 1179 | 1274 | |
| 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 | ||
| 1180 | 1282 | =begin original |
| 1181 | 1283 | |
| 1182 | 1284 | Characters that may carry a special meaning inside a character class are: |
| 1183 | 1285 | C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be |
| 1184 | 1286 | escaped with a backslash, although this is sometimes not needed, in which |
| 1185 | 1287 | case the backslash may be omitted. |
| 1186 | 1288 | |
| 1187 | 1289 | =end original |
| 1188 | 1290 | |
| 1189 | 1291 | 文字クラスの中でも特別な意味を持つ文字は: |
| 1190 | 1292 | C<\>, C<^>, C<->, C<[>, C<]> で、以下で議論します。 |
| 1191 | 1293 | これらは逆スラッシュでエスケープできますが、不要な場合もあり、そのような |
| 1192 | 1294 | 場合では逆スラッシュは省略できます。 |
| 1193 | 1295 | |
| 1194 | 1296 | =begin original |
| 1195 | 1297 | |
| 1196 | 1298 | The sequence C<\b> is special inside a bracketed character class. While |
| 1197 | 1299 | outside the character class, C<\b> is an assertion indicating a point |
| 1198 | 1300 | that does not have either two word characters or two non-word characters |
| 1199 | 1301 | on either side, inside a bracketed character class, C<\b> matches a |
| 1200 | 1302 | backspace character. |
| 1201 | 1303 | |
| 1202 | 1304 | =end original |
| 1203 | 1305 | |
| 1204 | 1306 | シーケンス C<\b> は大かっこ文字クラスの内側では特別です。 |
| 1205 | 1307 | 文字クラスの外側では C<\b> 二つの単語文字か二つの非単語文字のどちらかではない |
| 1206 | 1308 | 位置を示す表明ですが、大かっこ文字クラスの内側では C<\b> は後退文字に |
| 1207 | 1309 | マッチングします。 |
| 1208 | 1310 | |
| 1209 | 1311 | =begin original |
| 1210 | 1312 | |
| 1211 | 1313 | The sequences |
| 1212 | 1314 | C<\a>, |
| 1213 | 1315 | C<\c>, |
| 1214 | 1316 | C<\e>, |
| 1215 | 1317 | C<\f>, |
| 1216 | 1318 | C<\n>, |
| 1217 | 1319 | C<\N{I<NAME>}>, |
| 1218 | 1320 | C<\N{U+I<hex char>}>, |
| 1219 | 1321 | C<\r>, |
| 1220 | 1322 | C<\t>, |
| 1221 | 1323 | and |
| 1222 | 1324 | C<\x> |
| 1223 | 1325 | are also special and have the same meanings as they do outside a |
| 1224 | bracketed character class. | |
| 1326 | bracketed character class. | |
| 1225 | class, if C<\N{I<NAME>}> expands to a sequence of characters, only the first | |
| 1226 | one in the sequence is used, with a warning.) | |
| 1227 | 1327 | |
| 1228 | 1328 | =end original |
| 1229 | 1329 | |
| 1230 | 1330 | 並び |
| 1231 | 1331 | C<\a>, |
| 1232 | 1332 | C<\c>, |
| 1233 | 1333 | C<\e>, |
| 1234 | 1334 | C<\f>, |
| 1235 | 1335 | C<\n>, |
| 1236 | 1336 | C<\N{I<NAME>}>, |
| 1237 | 1337 | C<\N{U+I<hex char>}>, |
| 1238 | 1338 | C<\r>, |
| 1239 | 1339 | C<\t>, |
| 1240 | 1340 | C<\x> |
| 1241 | 1341 | も特別で、大かっこ文字クラスの外側と同じ意味を持ちます。 |
| 1242 | (しかし、大かっこ文字クラスの中では、 | |
| 1243 | C<\N{I<NAME>}> が文字並びに展開されると、 | |
| 1244 | 並びの最初の一つだけが使われ、警告が発生します。) | |
| 1245 | 1342 | |
| 1246 | 1343 | =begin original |
| 1247 | 1344 | |
| 1248 | 1345 | Also, a backslash followed by two or three octal digits is considered an octal |
| 1249 | 1346 | number. |
| 1250 | 1347 | |
| 1251 | 1348 | =end original |
| 1252 | 1349 | |
| 1253 | 1350 | また、逆スラッシュに引き続いて 2 または 3 桁の 8 進数字があると 8 進数として |
| 1254 | 1351 | 扱われます。 |
| 1255 | 1352 | |
| 1256 | 1353 | =begin original |
| 1257 | 1354 | |
| 1258 | 1355 | A C<[> is not special inside a character class, unless it's the start of a |
| 1259 | 1356 | POSIX character class (see L</POSIX Character Classes> below). It normally does |
| 1260 | 1357 | not need escaping. |
| 1261 | 1358 | |
| 1262 | 1359 | =end original |
| 1263 | 1360 | |
| 1264 | 1361 | C<[> は、POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の |
| 1265 | 1362 | 開始でない限りは文字クラスの中では特別ではありません。 |
| 1266 | 1363 | これは普通エスケープは不要です。 |
| 1267 | 1364 | |
| 1268 | 1365 | =begin original |
| 1269 | 1366 | |
| 1270 | 1367 | A C<]> is normally either the end of a POSIX character class (see |
| 1271 | 1368 | L</POSIX Character Classes> below), or it signals the end of the bracketed |
| 1272 | 1369 | character class. If you want to include a C<]> in the set of characters, you |
| 1273 | 1370 | must generally escape it. |
| 1274 | 1371 | |
| 1275 | 1372 | =end original |
| 1276 | 1373 | |
| 1277 | 1374 | A C<]> は普通は POSIX 文字クラス(後述の L</POSIX Character Classes> 参照)の |
| 1278 | 1375 | 終わりか、大かっこ文字クラスの終了を示すかどちらかです。 |
| 1279 | 1376 | 文字集合に C<]> を含める必要がある場合、一般的には |
| 1280 | 1377 | エスケープしなければなりません。 |
| 1281 | 1378 | |
| 1282 | 1379 | =begin original |
| 1283 | 1380 | |
| 1284 | 1381 | However, if the C<]> is the I<first> (or the second if the first |
| 1285 | 1382 | character is a caret) character of a bracketed character class, it |
| 1286 | 1383 | does not denote the end of the class (as you cannot have an empty class) |
| 1287 | 1384 | and is considered part of the set of characters that can be matched without |
| 1288 | 1385 | escaping. |
| 1289 | 1386 | |
| 1290 | 1387 | =end original |
| 1291 | 1388 | |
| 1292 | 1389 | しかし、C<]> が大かっこ文字クラスの I<最初> (または最初の文字がキャレットなら |
| 1293 | 1390 | 2 番目) の文字の場合、(空クラスを作ることはできないので)これはクラスの |
| 1294 | 1391 | 終了を意味せず、エスケープなしでマッチングできる文字の集合の一部と |
| 1295 | 1392 | 考えられます。 |
| 1296 | 1393 | |
| 1297 | 1394 | =begin original |
| 1298 | 1395 | |
| 1299 | 1396 | Examples: |
| 1300 | 1397 | |
| 1301 | 1398 | =end original |
| 1302 | 1399 | |
| 1303 | 1400 | 例: |
| 1304 | 1401 | |
| 1305 | 1402 | =begin original |
| 1306 | 1403 | |
| 1307 | 1404 | "+" =~ /[+?*]/ # Match, "+" in a character class is not special. |
| 1308 | "\cH" =~ /[\b]/ # Match, \b inside in a character class | |
| 1405 | "\cH" =~ /[\b]/ # Match, \b inside in a character class | |
| 1309 | 1406 | # is equivalent to a backspace. |
| 1310 | "]" =~ /[][]/ # Match, as the character class contains | |
| 1407 | "]" =~ /[][]/ # Match, as the character class contains | |
| 1311 | 1408 | # both [ and ]. |
| 1312 | 1409 | "[]" =~ /[[]]/ # Match, the pattern contains a character class |
| 1313 | # containing just | |
| 1410 | # containing just [, and the character class is | |
| 1314 | 1411 | # followed by a ]. |
| 1315 | 1412 | |
| 1316 | 1413 | =end original |
| 1317 | 1414 | |
| 1318 | 1415 | "+" =~ /[+?*]/ # マッチング; 文字クラス内の "+" は特別ではない。 |
| 1319 | 1416 | "\cH" =~ /[\b]/ # マッチング; 文字クラスの内側の \b は後退と |
| 1320 | 1417 | # 等価。 |
| 1321 | 1418 | "]" =~ /[][]/ # マッチング; 文字クラスに [ と ] の両方を |
| 1322 | 1419 | # 含んでいる。 |
| 1323 | "[]" =~ /[[]]/ # マッチング; パターンは | |
| 1420 | "[]" =~ /[[]]/ # マッチング; パターンは [ だけを含んでいる | |
| 1324 | 1421 | # 文字クラスと、それに引き続く |
| 1325 | 1422 | # ] からなる。 |
| 1326 | 1423 | |
| 1424 | =head3 Bracketed Character Classes and the C</xx> pattern modifier | |
| 1425 | ||
| 1426 | =begin original | |
| 1427 | ||
| 1428 | Normally SPACE and TAB characters have no special meaning inside a | |
| 1429 | bracketed character class; they are just added to the list of characters | |
| 1430 | matched by the class. But if the L<C</xx>|perlre/E<sol>x and E<sol>xx> | |
| 1431 | pattern modifier is in effect, they are generally ignored and can be | |
| 1432 | added to improve readability. They can't be added in the middle of a | |
| 1433 | single 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 | ||
| 1448 | The SPACE in the middle of the hex constant is illegal. | |
| 1449 | ||
| 1450 | =end original | |
| 1451 | ||
| 1452 | 16 進定数の中の SPACE は不正です。 | |
| 1453 | ||
| 1454 | =begin original | |
| 1455 | ||
| 1456 | To specify a literal SPACE character, you can escape it with a | |
| 1457 | backslash, like: | |
| 1458 | ||
| 1459 | =end original | |
| 1460 | ||
| 1461 | リテラルな SPACE 文字を指定するには、次のように逆スラッシュで | |
| 1462 | エスケープします: | |
| 1463 | ||
| 1464 | /[ a e i o u \ ]/xx | |
| 1465 | ||
| 1466 | =begin original | |
| 1467 | ||
| 1468 | This matches the English vowels plus the SPACE character. | |
| 1469 | ||
| 1470 | =end original | |
| 1471 | ||
| 1472 | これは英語の母音と SPACE 文字に一致します。 | |
| 1473 | ||
| 1474 | =begin original | |
| 1475 | ||
| 1476 | For clarity, you should already have been using C<\t> to specify a | |
| 1477 | literal tab, and C<\t> is unaffected by C</xx>. | |
| 1478 | ||
| 1479 | =end original | |
| 1480 | ||
| 1481 | 確認すると、リテラルなタブのためには既に C<\t> を使っているべきで、 | |
| 1482 | C<\t> は C</xx> の影響を受けません。 | |
| 1483 | ||
| 1327 | 1484 | =head3 Character Ranges |
| 1328 | 1485 | |
| 1329 | 1486 | (文字範囲) |
| 1330 | 1487 | |
| 1331 | 1488 | =begin original |
| 1332 | 1489 | |
| 1333 | 1490 | It is not uncommon to want to match a range of characters. Luckily, instead |
| 1334 | 1491 | of listing all characters in the range, one may use the hyphen (C<->). |
| 1335 | 1492 | If inside a bracketed character class you have two characters separated |
| 1336 | 1493 | by a hyphen, it's treated as if all characters between the two were in |
| 1337 | 1494 | the class. For instance, C<[0-9]> matches any ASCII digit, and C<[a-m]> |
| 1338 | 1495 | matches any lowercase letter from the first half of the ASCII alphabet. |
| 1339 | 1496 | |
| 1340 | 1497 | =end original |
| 1341 | 1498 | |
| 1342 | 1499 | 文字のある範囲にマッチングしたいというのは珍しくありません。 |
| 1343 | 1500 | 幸運なことに、その範囲の文字を全て一覧に書く代わりに、ハイフン (C<->) を |
| 1344 | 1501 | 使えます。 |
| 1345 | 1502 | 大かっこ文字クラスの内側で二つの文字がハイフンで区切られていると、 |
| 1346 | 1503 | 二つの文字の間の全ての文字がクラスに書かれているかのように扱われます。 |
| 1347 | 1504 | 例えば、C<[0-9]> は任意の ASCII 数字にマッチングし、C<[a-m]> は |
| 1348 | 1505 | ASCII アルファベットの前半分の小文字にマッチングします。 |
| 1349 | 1506 | |
| 1350 | 1507 | =begin original |
| 1351 | 1508 | |
| 1352 | 1509 | Note that the two characters on either side of the hyphen are not |
| 1353 | 1510 | necessarily both letters or both digits. Any character is possible, |
| 1354 | 1511 | although not advisable. C<['-?]> contains a range of characters, but |
| 1355 | 1512 | most people will not know which characters that means. Furthermore, |
| 1356 | 1513 | such ranges may lead to portability problems if the code has to run on |
| 1357 | 1514 | a platform that uses a different character set, such as EBCDIC. |
| 1358 | 1515 | |
| 1359 | 1516 | =end original |
| 1360 | 1517 | |
| 1361 | 1518 | ハイフンのそれぞれの側の二つの文字は両方とも英字であったり両方とも |
| 1362 | 1519 | 数字であったりする必要はないことに注意してください。 |
| 1363 | 1520 | 任意の文字が可能ですが、勧められません。 |
| 1364 | 1521 | C<['-?]> は文字の範囲を含みますが、ほとんどの人はどの文字が含まれるか |
| 1365 | 1522 | 分かりません。 |
| 1366 | 1523 | さらに、このような範囲は、コードが EBCDIC のような異なった文字集合を使う |
| 1367 | 1524 | プラットフォームで実行されると移植性の問題を引き起こします。 |
| 1368 | 1525 | |
| 1369 | 1526 | =begin original |
| 1370 | 1527 | |
| 1371 | 1528 | If a hyphen in a character class cannot syntactically be part of a range, for |
| 1372 | 1529 | instance because it is the first or the last character of the character class, |
| 1373 | 1530 | or if it immediately follows a range, the hyphen isn't special, and so is |
| 1374 | 1531 | considered a character to be matched literally. If you want a hyphen in |
| 1375 | 1532 | your set of characters to be matched and its position in the class is such |
| 1376 | 1533 | that it could be considered part of a range, you must escape that hyphen |
| 1377 | 1534 | with a backslash. |
| 1378 | 1535 | |
| 1379 | 1536 | =end original |
| 1380 | 1537 | |
| 1381 | 1538 | 例えば文字クラスの最初または最後であったり、範囲の直後のために、文字クラスの |
| 1382 | 1539 | 中のハイフンが文法的に範囲の一部となれない場合、ハイフンは特別ではなく、 |
| 1383 | 1540 | リテラルにマッチングするべき文字として扱われます。 |
| 1384 | 1541 | マッチングする文字の集合にハイフンを入れたいけれどもその位置が範囲の |
| 1385 | 1542 | 一部として考えられる場合はハイフンを逆スラッシュで |
| 1386 | 1543 | エスケープしなければなりません。 |
| 1387 | 1544 | |
| 1388 | 1545 | =begin original |
| 1389 | 1546 | |
| 1390 | 1547 | Examples: |
| 1391 | 1548 | |
| 1392 | 1549 | =end original |
| 1393 | 1550 | |
| 1394 | 1551 | 例: |
| 1395 | 1552 | |
| 1396 | 1553 | =begin original |
| 1397 | 1554 | |
| 1398 | 1555 | [a-z] # Matches a character that is a lower case ASCII letter. |
| 1399 | 1556 | [a-fz] # Matches any letter between 'a' and 'f' (inclusive) or |
| 1400 | 1557 | # the letter 'z'. |
| 1401 | 1558 | [-z] # Matches either a hyphen ('-') or the letter 'z'. |
| 1402 | 1559 | [a-f-m] # Matches any letter between 'a' and 'f' (inclusive), the |
| 1403 | 1560 | # hyphen ('-'), or the letter 'm'. |
| 1404 | 1561 | ['-?] # Matches any of the characters '()*+,-./0123456789:;<=>? |
| 1405 | 1562 | # (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 "?") | |
| 1406 | 1567 | |
| 1407 | 1568 | =end original |
| 1408 | 1569 | |
| 1409 | 1570 | [a-z] # 小文字 ASCII 英字にマッチング。 |
| 1410 | 1571 | [a-fz] # 'a' から 'f' の英字およびと 'z' の英字に |
| 1411 | 1572 | # マッチング。 |
| 1412 | 1573 | [-z] # ハイフン ('-') または英字 'z' にマッチング。 |
| 1413 | 1574 | [a-f-m] # 'a' から 'f' の英字、ハイフン ('-')、英字 'm' に |
| 1414 | 1575 | # マッチング。 |
| 1415 | 1576 | ['-?] # 文字 '()*+,-./0123456789:;<=>? のどれかにマッチング |
| 1416 | 1577 | # (しかし EBCDIC プラットフォームでは異なります)。 |
| 1578 | [\N{APOSTROPHE}-\N{QUESTION MARK}] | |
| 1579 | # たとえ EBCDIC プラットフォームでも '()*+,-./0123456789:;<=>? | |
| 1580 | # のいずれかの文字にマッチング。 | |
| 1581 | [\N{U+27}-\N{U+3F}] # 同じ。 (U+27 は "'", U+3F は "?") | |
| 1417 | 1582 | |
| 1583 | =begin original | |
| 1584 | ||
| 1585 | As the final two examples above show, you can achieve portability to | |
| 1586 | non-ASCII platforms by using the C<\N{...}> form for the range | |
| 1587 | endpoints. These indicate that the specified range is to be interpreted | |
| 1588 | using Unicode values, so C<[\N{U+27}-\N{U+3F}]> means to match | |
| 1589 | C<\N{U+27}>, C<\N{U+28}>, C<\N{U+29}>, ..., C<\N{U+3D}>, C<\N{U+3E}>, | |
| 1590 | and C<\N{U+3F}>, whatever the native code point versions for those are. | |
| 1591 | These are called "Unicode" ranges. If either end is of the C<\N{...}> | |
| 1592 | form, the range is considered Unicode. A C<regexp> warning is raised | |
| 1593 | under C<S<"use re 'strict'">> if the other endpoint is specified | |
| 1594 | non-portably: | |
| 1595 | ||
| 1596 | =end original | |
| 1597 | ||
| 1598 | 前述の最後の二つの例が示すように、範囲の端点に | |
| 1599 | C<\N{...}> 形式を使用することで、非 ASCII プラットフォームへの | |
| 1600 | 移植性を実現できます。 | |
| 1601 | これらは、指定された範囲が Unicode 値を使用して解釈されることを示しています; | |
| 1602 | したがって、C<[\N{U+27}-\N{U+3F}]>は、C<\N{U+27}>、C<\N{U+28}>、 | |
| 1603 | C<\N{U+29}>、...、C<\N{U+3D}>、C<\N{U+3E}>、C<\N{U+3F}> に | |
| 1604 | マッチングすることを意味します; | |
| 1605 | これらのネイティブ符号位置のバージョンが何であっても一致します。 | |
| 1606 | これらは "Unicode" 範囲と呼ばれます。 | |
| 1607 | いずれかの端点が C<\N{...}> 形式の場合、範囲は Unicode と見なされます。 | |
| 1608 | もう一方の端点が移植性がない形で指定されている場合、 | |
| 1609 | C<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 | ||
| 1616 | Both of the above match the characters C<\N{U+00}> C<\N{U+01}>, ... | |
| 1617 | C<\N{U+08}>, C<\N{U+09}>, but the C<\x09> looks like it could be a | |
| 1618 | mistake 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}>, ... | |
| 1623 | C<\N{U+08}>, C<\N{U+09}> にマッチングしますが、 | |
| 1624 | C<\x09> は誤りのように見えるので、 | |
| 1625 | (C<re 'strict'> の下で) 警告が発生します。 | |
| 1626 | ||
| 1627 | =begin original | |
| 1628 | ||
| 1629 | Perl also guarantees that the ranges C<A-Z>, C<a-z>, C<0-9>, and any | |
| 1630 | subranges of these match what an English-only speaker would expect them | |
| 1631 | to match on any platform. That is, C<[A-Z]> matches the 26 ASCII | |
| 1632 | uppercase letters; | |
| 1633 | C<[a-z]> matches the 26 lowercase letters; and C<[0-9]> matches the 10 | |
| 1634 | digits. Subranges, like C<[h-k]>, match correspondingly, in this case | |
| 1635 | just the four letters C<"h">, C<"i">, C<"j">, and C<"k">. This is the | |
| 1636 | natural behavior on ASCII platforms where the code points (ordinal | |
| 1637 | values) for C<"h"> through C<"k"> are consecutive integers (0x68 through | |
| 1638 | 0x6B). But special handling to achieve this may be needed on platforms | |
| 1639 | with a non-ASCII native character set. For example, on EBCDIC | |
| 1640 | platforms, the code point for C<"h"> is 0x88, C<"i"> is 0x89, C<"j"> is | |
| 1641 | 0x91, and C<"k"> is 0x92. Perl specially treats C<[h-k]> to exclude the | |
| 1642 | seven code points in the gap: 0x8A through 0x90. This special handling is | |
| 1643 | only invoked when the range is a subrange of one of the ASCII uppercase, | |
| 1644 | lowercase, and digit ranges, AND each end of the range is expressed | |
| 1645 | either as a literal, like C<"A">, or as a named character (C<\N{...}>, | |
| 1646 | including the C<\N{U+...> form). | |
| 1647 | ||
| 1648 | =end original | |
| 1649 | ||
| 1650 | Perl はまた、範囲 C<A-Z>、C<a-z>、C<0-9>、およびこれらの部分範囲が、 | |
| 1651 | 英語のみの話者が一致すると予想する範囲とどのプラットフォームでも | |
| 1652 | 一致することを保証します。 | |
| 1653 | つまり、C<[A-Z]> はASCII の大文字 26 文字と一致します; | |
| 1654 | C<[a-z]> は小文字 26 文字と一致します; | |
| 1655 | C<[0-9]>は 10 の数字と一致します。 | |
| 1656 | C<[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"> のコードポイントは | |
| 1663 | 0x88、C<"i"> は 0x89、C<"j"> は 0x91、C<"k"> は 0x92 です。 | |
| 1664 | Perl は C<[h-k]> を特別に扱い、隙間にある七つの符号位置 | |
| 1665 | (0x8A から 0x90)を除外します。 | |
| 1666 | この特殊処理は、範囲が ASCII の大文字、小文字、数字の範囲の | |
| 1667 | いずれかの部分範囲であり、範囲の両端が C<"A"> のようなリテラル | |
| 1668 | または名前付き文字(C<\N{...}>(C<\N{U+...> 形式を含む))として表現されている | |
| 1669 | 場合にのみ呼び出されます。 | |
| 1670 | ||
| 1671 | =begin original | |
| 1672 | ||
| 1673 | EBCDIC Examples: | |
| 1674 | ||
| 1675 | =end original | |
| 1676 | ||
| 1677 | EBCDIC の例: | |
| 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 | ||
| 1418 | 1690 | =head3 Negation |
| 1419 | 1691 | |
| 1420 | 1692 | (否定) |
| 1421 | 1693 | |
| 1422 | 1694 | =begin original |
| 1423 | 1695 | |
| 1424 | 1696 | It is also possible to instead list the characters you do not want to |
| 1425 | 1697 | match. You can do so by using a caret (C<^>) as the first character in the |
| 1426 | 1698 | character class. For instance, C<[^a-z]> matches any character that is not a |
| 1427 | 1699 | lowercase ASCII letter, which therefore includes more than a million |
| 1428 | 1700 | Unicode code points. The class is said to be "negated" or "inverted". |
| 1429 | 1701 | |
| 1430 | 1702 | =end original |
| 1431 | 1703 | |
| 1432 | 1704 | 代わりにマッチングしたくない文字の一覧を指定することも可能です。 |
| 1433 | 1705 | 文字クラスの先頭の文字としてキャレット (C<^>) を使うことで実現します。 |
| 1434 | 1706 | 例えば、C<[^a-z]> 小文字の ASCII 英字以外の文字にマッチングします; |
| 1435 | 1707 | 従って 100 万種類以上の Unicode 符号位置が含まれます。 |
| 1436 | 1708 | このクラスは「否定」("negated") や「反転」("inverted")と呼ばれます。 |
| 1437 | 1709 | |
| 1438 | 1710 | =begin original |
| 1439 | 1711 | |
| 1440 | 1712 | This syntax make the caret a special character inside a bracketed character |
| 1441 | 1713 | class, but only if it is the first character of the class. So if you want |
| 1442 | 1714 | the caret as one of the characters to match, either escape the caret or |
| 1443 | 1715 | else don't list it first. |
| 1444 | 1716 | |
| 1445 | 1717 | =end original |
| 1446 | 1718 | |
| 1447 | 1719 | この文法はキャレットを大かっこ文字クラスの内側で特別な文字にしますが、 |
| 1448 | 1720 | クラスの最初の文字の場合のみです。 |
| 1449 | 1721 | それでマッチングしたい文字の一つでキャレットを使いたい場合、キャレットを |
| 1450 | 1722 | エスケープするか、最初以外の位置に書いてください。 |
| 1451 | 1723 | |
| 1452 | 1724 | =begin original |
| 1453 | 1725 | |
| 1454 | 1726 | In inverted bracketed character classes, Perl ignores the Unicode rules |
| 1455 | that normally say that certain characters should | |
| 1727 | that normally say that named sequence, and certain characters should | |
| 1456 | multiple characters under caseless C</i> | |
| 1728 | match a sequence of multiple characters use under caseless C</i> | |
| 1457 | rules could lead to highly confusing | |
| 1729 | matching. Following those rules could lead to highly confusing | |
| 1730 | situations: | |
| 1458 | 1731 | |
| 1459 | 1732 | =end original |
| 1460 | 1733 | |
| 1461 | 1734 | 否定大かっこ文字クラスでは、通常は大文字小文字を無視した C</i> マッチングの |
| 1462 | 下ではある種の文字が複数の文字並びにマッチングするということを | |
| 1735 | 下では名前空間とある種の文字が複数の文字並びにマッチングするということを | |
| 1463 | 1736 | Perl は無視します。 |
| 1464 | 1737 | これらの規則に従うととても混乱する状況を引き起こすことになるからです: |
| 1465 | 1738 | |
| 1466 | 1739 | "ss" =~ /^[^\xDF]+$/ui; # Matches! |
| 1467 | 1740 | |
| 1468 | 1741 | =begin original |
| 1469 | 1742 | |
| 1470 | 1743 | This should match any sequences of characters that aren't C<\xDF> nor |
| 1471 | 1744 | what C<\xDF> matches under C</i>. C<"s"> isn't C<\xDF>, but Unicode |
| 1472 | 1745 | says that C<"ss"> is what C<\xDF> matches under C</i>. So which one |
| 1473 | 1746 | "wins"? Do you fail the match because the string has C<ss> or accept it |
| 1474 | 1747 | because it has an C<s> followed by another C<s>? Perl has chosen the |
| 1475 | latter. | |
| 1748 | latter. (See note in L</Bracketed Character Classes> above.) | |
| 1476 | 1749 | |
| 1477 | 1750 | =end original |
| 1478 | 1751 | |
| 1479 | 1752 | これは C</i> の下では C<\xDF> または C<\xDF> にマッチングするもの以外の |
| 1480 | 1753 | 任意の文字並びにマッチングするべきです。 |
| 1481 | 1754 | C<"s"> は C<\xDF> ではありませんが、 |
| 1482 | 1755 | C</i> の下では C<"ss"> は C<\xDF> がマッチングするものと Unicode は |
| 1483 | 1756 | 言っています。 |
| 1484 | 1757 | ではどちらが「勝つ」のでしょうか? |
| 1485 | 1758 | 文字列は C<ss> だからマッチングに失敗するのでしょうか、 |
| 1486 | 1759 | それともこれは C<s> の後にもう一つの C<s> があるから成功するのでしょうか? |
| 1487 | 1760 | Perl は後者を選択しました。 |
| 1761 | (前述の L</Bracketed Character Classes> を参照してください。) | |
| 1488 | 1762 | |
| 1489 | 1763 | =begin original |
| 1490 | 1764 | |
| 1491 | 1765 | Examples: |
| 1492 | 1766 | |
| 1493 | 1767 | =end original |
| 1494 | 1768 | |
| 1495 | 1769 | 例: |
| 1496 | 1770 | |
| 1497 | 1771 | =begin original |
| 1498 | 1772 | |
| 1499 | 1773 | "e" =~ /[^aeiou]/ # No match, the 'e' is listed. |
| 1500 | 1774 | "x" =~ /[^aeiou]/ # Match, as 'x' isn't a lowercase vowel. |
| 1501 | 1775 | "^" =~ /[^^]/ # No match, matches anything that isn't a caret. |
| 1502 | 1776 | "^" =~ /[x^]/ # Match, caret is not special here. |
| 1503 | 1777 | |
| 1504 | 1778 | =end original |
| 1505 | 1779 | |
| 1506 | 1780 | "e" =~ /[^aeiou]/ # マッチングしない; 'e' がある。 |
| 1507 | 1781 | "x" =~ /[^aeiou]/ # マッチング; 'x' は小文字の母音ではない。 |
| 1508 | 1782 | "^" =~ /[^^]/ # マッチングしない; キャレット以外全てにマッチング。 |
| 1509 | 1783 | "^" =~ /[x^]/ # マッチング; キャレットはここでは特別ではない。 |
| 1510 | 1784 | |
| 1511 | 1785 | =head3 Backslash Sequences |
| 1512 | 1786 | |
| 1513 | 1787 | (逆スラッシュシーケンス) |
| 1514 | 1788 | |
| 1515 | 1789 | =begin original |
| 1516 | 1790 | |
| 1517 | 1791 | You can put any backslash sequence character class (with the exception of |
| 1518 | 1792 | C<\N> and C<\R>) inside a bracketed character class, and it will act just |
| 1519 | 1793 | as if you had put all characters matched by the backslash sequence inside the |
| 1520 | 1794 | character class. For instance, C<[a-f\d]> matches any decimal digit, or any |
| 1521 | 1795 | of the lowercase letters between 'a' and 'f' inclusive. |
| 1522 | 1796 | |
| 1523 | 1797 | =end original |
| 1524 | 1798 | |
| 1525 | 1799 | 大かっこ文字クラスの中に(C<\N> と C<\R> を例外として)逆スラッシュシーケンス |
| 1526 | 1800 | 文字クラスを置くことができ、逆スラッシュシーケンスにマッチングする全ての |
| 1527 | 1801 | 文字を文字クラスの中に置いたかのように動作します。 |
| 1528 | 1802 | 例えば、C<[a-f\d]> は任意の 10 進数字、あるいは 'a' から 'f' までの小文字に |
| 1529 | 1803 | マッチングします。 |
| 1530 | 1804 | |
| 1531 | 1805 | =begin original |
| 1532 | 1806 | |
| 1533 | 1807 | C<\N> within a bracketed character class must be of the forms C<\N{I<name>}> |
| 1534 | 1808 | or C<\N{U+I<hex char>}>, and NOT be the form that matches non-newlines, |
| 1535 | 1809 | for the same reason that a dot C<.> inside a bracketed character class loses |
| 1536 | 1810 | its special meaning: it matches nearly anything, which generally isn't what you |
| 1537 | 1811 | want to happen. |
| 1538 | 1812 | |
| 1539 | 1813 | =end original |
| 1540 | 1814 | |
| 1541 | 1815 | 大かっこ文字クラスの中のドット C<.> が特別な意味を持たないのと同じ理由で、 |
| 1542 | 1816 | 大かっこ文字クラスの中の C<\N> は C<\N{I<name>}> または |
| 1543 | 1817 | C<\N{U+I<hex char>}> の形式で、かつ非改行マッチング形式でない形でなければ |
| 1544 | 1818 | なりません: これはほとんど何でもマッチングするので、一般的には起こって |
| 1545 | 1819 | 欲しいことではありません。 |
| 1546 | 1820 | |
| 1547 | 1821 | =begin original |
| 1548 | 1822 | |
| 1549 | 1823 | Examples: |
| 1550 | 1824 | |
| 1551 | 1825 | =end original |
| 1552 | 1826 | |
| 1553 | 1827 | 例: |
| 1554 | 1828 | |
| 1555 | 1829 | =begin original |
| 1556 | 1830 | |
| 1557 | 1831 | /[\p{Thai}\d]/ # Matches a character that is either a Thai |
| 1558 | 1832 | # character, or a digit. |
| 1559 | 1833 | /[^\p{Arabic}()]/ # Matches a character that is neither an Arabic |
| 1560 | 1834 | # character, nor a parenthesis. |
| 1561 | 1835 | |
| 1562 | 1836 | =end original |
| 1563 | 1837 | |
| 1564 | 1838 | /[\p{Thai}\d]/ # タイ文字または数字の文字に |
| 1565 | 1839 | # マッチングする。 |
| 1566 | 1840 | /[^\p{Arabic}()]/ # アラビア文字でもかっこでもない文字に |
| 1567 | 1841 | # マッチングする。 |
| 1568 | 1842 | |
| 1569 | 1843 | =begin original |
| 1570 | 1844 | |
| 1571 | 1845 | Backslash sequence character classes cannot form one of the endpoints |
| 1572 | 1846 | of a range. Thus, you can't say: |
| 1573 | 1847 | |
| 1574 | 1848 | =end original |
| 1575 | 1849 | |
| 1576 | 1850 | 逆スラッシュシーケンス文字クラスは範囲の端点の一つにはできません。 |
| 1577 | 1851 | 従って、以下のようにはできません: |
| 1578 | 1852 | |
| 1579 | 1853 | /[\p{Thai}-\d]/ # Wrong! |
| 1580 | 1854 | |
| 1581 | 1855 | =head3 POSIX Character Classes |
| 1582 | 1856 | X<character class> X<\p> X<\p{}> |
| 1583 | 1857 | X<alpha> X<alnum> X<ascii> X<blank> X<cntrl> X<digit> X<graph> |
| 1584 | 1858 | X<lower> X<print> X<punct> X<space> X<upper> X<word> X<xdigit> |
| 1585 | 1859 | |
| 1586 | 1860 | (POSIX 文字クラス) |
| 1587 | 1861 | |
| 1588 | 1862 | =begin original |
| 1589 | 1863 | |
| 1590 | POSIX character classes have the form C<[:class:]>, where I<class> is | |
| 1864 | POSIX character classes have the form C<[:class:]>, where I<class> is the | |
| 1591 | 1865 | name, and the C<[:> and C<:]> delimiters. POSIX character classes only appear |
| 1592 | 1866 | I<inside> bracketed character classes, and are a convenient and descriptive |
| 1593 | 1867 | way of listing a group of characters. |
| 1594 | 1868 | |
| 1595 | 1869 | =end original |
| 1596 | 1870 | |
| 1597 | 1871 | POSIX 文字クラスは C<[:class:]> の形式で、I<class> は名前、C<[:> と C<:]> は |
| 1598 | 1872 | デリミタです。 |
| 1599 | 1873 | POSIX 文字クラスは大かっこ文字クラスの I<内側> にのみ現れ、文字のグループを |
| 1600 | 1874 | 一覧するのに便利で記述的な方法です。 |
| 1601 | 1875 | |
| 1602 | 1876 | =begin original |
| 1603 | 1877 | |
| 1604 | 1878 | Be careful about the syntax, |
| 1605 | 1879 | |
| 1606 | 1880 | =end original |
| 1607 | 1881 | |
| 1608 | 1882 | 文法について注意してください、 |
| 1609 | 1883 | |
| 1610 | 1884 | # Correct: |
| 1611 | 1885 | $string =~ /[[:alpha:]]/ |
| 1612 | 1886 | |
| 1613 | 1887 | # Incorrect (will warn): |
| 1614 | 1888 | $string =~ /[:alpha:]/ |
| 1615 | 1889 | |
| 1616 | 1890 | =begin original |
| 1617 | 1891 | |
| 1618 | 1892 | The latter pattern would be a character class consisting of a colon, |
| 1619 | 1893 | and the letters C<a>, C<l>, C<p> and C<h>. |
| 1620 | 1894 | POSIX character classes can be part of a larger bracketed character class. |
| 1621 | 1895 | For example, |
| 1622 | 1896 | |
| 1623 | 1897 | =end original |
| 1624 | 1898 | |
| 1625 | 1899 | 後者のパターンは、コロンおよび C<a>, C<l>, C<p>, C<h> の文字からなる |
| 1626 | 1900 | 文字クラスです。 |
| 1627 | 1901 | これら文字クラスはより大きな大かっこ文字クラスの一部にできます。 |
| 1628 | 例えば | |
| 1902 | 例えば: | |
| 1629 | 1903 | |
| 1630 | 1904 | [01[:alpha:]%] |
| 1631 | 1905 | |
| 1632 | 1906 | =begin original |
| 1633 | 1907 | |
| 1634 | 1908 | is valid and matches '0', '1', any alphabetic character, and the percent sign. |
| 1635 | 1909 | |
| 1636 | 1910 | =end original |
| 1637 | 1911 | |
| 1638 | 1912 | これは妥当で、'0'、'1'、任意の英字、パーセントマークにマッチングします。 |
| 1639 | 1913 | |
| 1640 | 1914 | =begin original |
| 1641 | 1915 | |
| 1642 | 1916 | Perl recognizes the following POSIX character classes: |
| 1643 | 1917 | |
| 1644 | 1918 | =end original |
| 1645 | 1919 | |
| 1646 | 1920 | Perl は以下の POSIX 文字クラスを認識します: |
| 1647 | 1921 | |
| 1648 | 1922 | =begin original |
| 1649 | 1923 | |
| 1650 | alpha Any alphabetical character ( | |
| 1924 | alpha Any alphabetical character (e.g., [A-Za-z]). | |
| 1651 | alnum Any alphanumeric character ( | |
| 1925 | alnum Any alphanumeric character (e.g., [A-Za-z0-9]). | |
| 1652 | 1926 | ascii Any character in the ASCII character set. |
| 1653 | blank A | |
| 1927 | blank Any horizontal whitespace character (e.g. space or horizontal | |
| 1928 | tab ("\t")). | |
| 1654 | 1929 | cntrl Any control character. See Note [2] below. |
| 1655 | digit Any decimal digit ( | |
| 1930 | digit Any decimal digit (e.g., [0-9]), equivalent to "\d". | |
| 1656 | 1931 | graph Any printable character, excluding a space. See Note [3] below. |
| 1657 | lower Any lowercase character ( | |
| 1932 | lower Any lowercase character (e.g., [a-z]). | |
| 1658 | 1933 | print Any printable character, including a space. See Note [4] below. |
| 1659 | 1934 | punct Any graphical character excluding "word" characters. Note [5]. |
| 1660 | 1935 | space Any whitespace character. "\s" including the vertical tab |
| 1661 | 1936 | ("\cK"). |
| 1662 | upper Any uppercase character ( | |
| 1937 | upper Any uppercase character (e.g., [A-Z]). | |
| 1663 | word A Perl extension ( | |
| 1938 | word A Perl extension (e.g., [A-Za-z0-9_]), equivalent to "\w". | |
| 1664 | xdigit Any hexadecimal digit ( | |
| 1939 | xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]). Note [7]. | |
| 1665 | 1940 | |
| 1666 | 1941 | =end original |
| 1667 | 1942 | |
| 1668 | alpha 任意の英字 ( | |
| 1943 | alpha 任意の英字 (例: [A-Za-z])。 | |
| 1669 | alnum 任意の英数字。( | |
| 1944 | alnum 任意の英数字。(例: [A-Za-z0-9]) | |
| 1670 | 1945 | ascii 任意の ASCII 文字集合の文字。 |
| 1671 | blank | |
| 1946 | blank 任意の水平空白文字 (スペース、水平タブ ("\t") など) | |
| 1672 | 1947 | cntrl 任意の制御文字。後述の [2] 参照。 |
| 1673 | digit 任意の 10 進数字 ( | |
| 1948 | digit 任意の 10 進数字 (例: [0-9]); "\d" と等価。 | |
| 1674 | 1949 | graph 任意の表示文字; スペースを除く。後述の [3] 参照。 |
| 1675 | lower 任意の小文字 ( | |
| 1950 | lower 任意の小文字 (例: [a-z])。 | |
| 1676 | 1951 | print 任意の表示文字; スペースを含む。後述の [4] 参照。 |
| 1677 | 1952 | punct 任意の「単語」文字を除く表示文字。[5] 参照。 |
| 1678 | 1953 | space 任意の空白文字。水平タブ ("\cK") を含む "\s"。 |
| 1679 | upper 任意の大文字 ( | |
| 1954 | upper 任意の大文字 (例: [A-Z])。 | |
| 1680 | word Perl 拡張 ( | |
| 1955 | word Perl 拡張 (例: [A-Za-z0-9_]); "\w" と等価。 | |
| 1681 | xdigit 任意の 16 進文字 ( | |
| 1956 | xdigit 任意の 16 進文字 (例: [0-9a-fA-F])。[7] 参照。 | |
| 1682 | 1957 | |
| 1683 | 1958 | =begin original |
| 1684 | 1959 | |
| 1960 | Like the L<Unicode properties|/Unicode Properties>, most of the POSIX | |
| 1961 | properties match the same regardless of whether case-insensitive (C</i>) | |
| 1962 | matching is in effect or not. The two exceptions are C<[:upper:]> and | |
| 1963 | C<[:lower:]>. Under C</i>, they each match the union of C<[:upper:]> and | |
| 1964 | C<[:lower:]>. | |
| 1965 | ||
| 1966 | =end original | |
| 1967 | ||
| 1968 | L<Unicode properties|/Unicode Properties> と同様、 | |
| 1969 | ほとんどの POSIX 特性は、大文字小文字無視 (C</i>) が有効かどうかに関わらず | |
| 1970 | 同じものにマッチングします。 | |
| 1971 | 二つの例外は C<[:upper:]> と C<[:lower:]> です。 | |
| 1972 | C</i> の下では、これらそれぞれ C<[:upper:]> と C<[:lower:]> の和集合に | |
| 1973 | マッチングします。 | |
| 1974 | ||
| 1975 | =begin original | |
| 1976 | ||
| 1685 | 1977 | Most POSIX character classes have two Unicode-style C<\p> property |
| 1686 | 1978 | counterparts. (They are not official Unicode properties, but Perl extensions |
| 1687 | 1979 | derived from official Unicode properties.) The table below shows the relation |
| 1688 | 1980 | between POSIX character classes and these counterparts. |
| 1689 | 1981 | |
| 1690 | 1982 | =end original |
| 1691 | 1983 | |
| 1692 | 1984 | ほとんどの POSIX 文字クラスには、対応する二つの Unicode 式の C<\p> 特性が |
| 1693 | 1985 | あります。 |
| 1694 | 1986 | (これは公式 Unicode 特性ではなく、公式 Unicode 特性から派生した Perl |
| 1695 | 1987 | エクステンションです。) |
| 1696 | 1988 | 以下の表は POSIX 文字クラスと対応するものとの関連を示します。 |
| 1697 | 1989 | |
| 1698 | 1990 | =begin original |
| 1699 | 1991 | |
| 1700 | 1992 | One counterpart, in the column labelled "ASCII-range Unicode" in |
| 1701 | 1993 | the table, matches only characters in the ASCII character set. |
| 1702 | 1994 | |
| 1703 | 1995 | =end original |
| 1704 | 1996 | |
| 1705 | 1997 | 対応物の一つである、表で "ASCII-range Unicode" と書かれた列のものは、 |
| 1706 | 1998 | ASCII 文字集合の文字にのみマッチングします。 |
| 1707 | 1999 | |
| 1708 | 2000 | =begin original |
| 1709 | 2001 | |
| 1710 | 2002 | The other counterpart, in the column labelled "Full-range Unicode", matches any |
| 1711 | 2003 | appropriate characters in the full Unicode character set. For example, |
| 1712 | 2004 | C<\p{Alpha}> matches not just the ASCII alphabetic characters, but any |
| 1713 | 2005 | character in the entire Unicode character set considered alphabetic. |
| 1714 | 2006 | An entry in the column labelled "backslash sequence" is a (short) |
| 1715 | 2007 | equivalent. |
| 1716 | 2008 | |
| 1717 | 2009 | =end original |
| 1718 | 2010 | |
| 1719 | 2011 | もう一つの対応物である、"Full-range Unicode" と書かれた列のものは、 |
| 1720 | 2012 | Unicode 文字集合全体の中の適切な任意の文字にマッチングします。 |
| 1721 | 2013 | 例えば、C<\p{Alpha}> は単に ASCII アルファベット文字だけでなく、 |
| 1722 | 2014 | Unicode 文字集合全体の中からアルファベットと考えられる任意の文字に |
| 1723 | 2015 | マッチングします。 |
| 1724 | 2016 | "backslash sequence" の列は (短い) 同義語です。 |
| 1725 | 2017 | |
| 1726 | 2018 | [[:...:]] ASCII-range Full-range backslash Note |
| 1727 | 2019 | Unicode Unicode sequence |
| 1728 | 2020 | ----------------------------------------------------- |
| 1729 | 2021 | alpha \p{PosixAlpha} \p{XPosixAlpha} |
| 1730 | 2022 | alnum \p{PosixAlnum} \p{XPosixAlnum} |
| 1731 | 2023 | ascii \p{ASCII} |
| 1732 | 2024 | blank \p{PosixBlank} \p{XPosixBlank} \h [1] |
| 1733 | 2025 | or \p{HorizSpace} [1] |
| 1734 | 2026 | cntrl \p{PosixCntrl} \p{XPosixCntrl} [2] |
| 1735 | 2027 | digit \p{PosixDigit} \p{XPosixDigit} \d |
| 1736 | 2028 | graph \p{PosixGraph} \p{XPosixGraph} [3] |
| 1737 | 2029 | lower \p{PosixLower} \p{XPosixLower} |
| 1738 | 2030 | print \p{PosixPrint} \p{XPosixPrint} [4] |
| 1739 | 2031 | punct \p{PosixPunct} \p{XPosixPunct} [5] |
| 1740 | 2032 | \p{PerlSpace} \p{XPerlSpace} \s [6] |
| 1741 | 2033 | space \p{PosixSpace} \p{XPosixSpace} [6] |
| 1742 | 2034 | upper \p{PosixUpper} \p{XPosixUpper} |
| 1743 | 2035 | word \p{PosixWord} \p{XPosixWord} \w |
| 1744 | xdigit \p{PosixXDigit} \p{XPosixXDigit} | |
| 2036 | xdigit \p{PosixXDigit} \p{XPosixXDigit} [7] | |
| 1745 | 2037 | |
| 1746 | 2038 | =over 4 |
| 1747 | 2039 | |
| 1748 | 2040 | =item [1] |
| 1749 | 2041 | |
| 1750 | 2042 | =begin original |
| 1751 | 2043 | |
| 1752 | 2044 | C<\p{Blank}> and C<\p{HorizSpace}> are synonyms. |
| 1753 | 2045 | |
| 1754 | 2046 | =end original |
| 1755 | 2047 | |
| 1756 | 2048 | C<\p{Blank}> と C<\p{HorizSpace}> は同義語です。 |
| 1757 | 2049 | |
| 1758 | 2050 | =item [2] |
| 1759 | 2051 | |
| 1760 | 2052 | =begin original |
| 1761 | 2053 | |
| 1762 | 2054 | Control characters don't produce output as such, but instead usually control |
| 1763 | 2055 | the terminal somehow: for example, newline and backspace are control characters. |
| 1764 | In the ASCII range, characters whose code points are | |
| 2056 | On ASCII platforms, in the ASCII range, characters whose code points are | |
| 1765 | plus 127 (C<DEL>) are control characters | |
| 2057 | between 0 and 31 inclusive, plus 127 (C<DEL>) are control characters; on | |
| 2058 | EBCDIC platforms, their counterparts are control characters. | |
| 1766 | 2059 | |
| 1767 | 2060 | =end original |
| 1768 | 2061 | |
| 1769 | 2062 | 制御文字はそれ自体は出力されず、普通は何か端末を制御します: 例えば |
| 1770 | 2063 | 改行と後退は制御文字です。 |
| 1771 | ASCII の範囲では、符号位置が 0 から 31 までの | |
| 2064 | ASCII プラットフォームで、ASCII の範囲では、符号位置が 0 から 31 までの | |
| 1772 | 制御文字です | |
| 2065 | 範囲の文字および 127 (C<DEL>) が制御文字です; | |
| 2066 | EBCDIC プラットフォームでは、対応するものは制御文字です。 | |
| 1773 | 2067 | |
| 1774 | 2068 | =item [3] |
| 1775 | 2069 | |
| 1776 | 2070 | =begin original |
| 1777 | 2071 | |
| 1778 | 2072 | Any character that is I<graphical>, that is, visible. This class consists |
| 1779 | 2073 | of all alphanumeric characters and all punctuation characters. |
| 1780 | 2074 | |
| 1781 | 2075 | =end original |
| 1782 | 2076 | |
| 1783 | 2077 | I<graphical>、つまり見える文字。 |
| 1784 | 2078 | このクラスは全ての英数字と全ての句読点文字。 |
| 1785 | 2079 | |
| 1786 | 2080 | =item [4] |
| 1787 | 2081 | |
| 1788 | 2082 | =begin original |
| 1789 | 2083 | |
| 1790 | 2084 | All printable characters, which is the set of all graphical characters |
| 1791 | 2085 | plus those whitespace characters which are not also controls. |
| 1792 | 2086 | |
| 1793 | 2087 | =end original |
| 1794 | 2088 | |
| 1795 | 2089 | 全ての表示可能な文字; 全ての graphical 文字に加えて制御文字でない空白文字。 |
| 1796 | 2090 | |
| 1797 | 2091 | =item [5] |
| 1798 | 2092 | |
| 1799 | 2093 | =begin original |
| 1800 | 2094 | |
| 1801 | 2095 | C<\p{PosixPunct}> and C<[[:punct:]]> in the ASCII range match all |
| 1802 | 2096 | non-controls, non-alphanumeric, non-space characters: |
| 1803 | 2097 | C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (although if a locale is in effect, |
| 1804 | 2098 | it could alter the behavior of C<[[:punct:]]>). |
| 1805 | 2099 | |
| 1806 | 2100 | =end original |
| 1807 | 2101 | |
| 1808 | 2102 | ASCII の範囲の C<\p{PosixPunct}> と C<[[:punct:]]> は全ての非制御、非英数字、 |
| 1809 | 2103 | 非空白文字にマッチングします: |
| 1810 | 2104 | C<[-!"#$%&'()*+,./:;<=E<gt>?@[\\\]^_`{|}~]> (しかしロケールが有効なら、 |
| 1811 | 2105 | C<[[:punct:]]> の振る舞いが変わります)。 |
| 1812 | 2106 | |
| 1813 | 2107 | =begin original |
| 1814 | 2108 | |
| 1815 | 2109 | The similarly named property, C<\p{Punct}>, matches a somewhat different |
| 1816 | 2110 | set in the ASCII range, namely |
| 1817 | 2111 | C<[-!"#%&'()*,./:;?@[\\\]_{}]>. That is, it is missing the nine |
| 1818 | 2112 | characters C<[$+E<lt>=E<gt>^`|~]>. |
| 1819 | 2113 | This is because Unicode splits what POSIX considers to be punctuation into two |
| 1820 | 2114 | categories, Punctuation and Symbols. |
| 1821 | 2115 | |
| 1822 | 2116 | =end original |
| 1823 | 2117 | |
| 1824 | 2118 | 似たような名前の特性 C<\p{Punct}> は、ASCII 範囲の異なる集合である |
| 1825 | 2119 | C<[-!"#%&'()*,./:;?@[\\\]_{}]> にマッチングします。 |
| 1826 | 2120 | つまり、C<[$+E<lt>=E<gt>^`|~]> の 9 文字はありません。 |
| 1827 | 2121 | これは、Unicode は POSIX が句読点と考えるものを二つのカテゴリ |
| 1828 | 2122 | Punctuation と Symbols に分けているからです。 |
| 1829 | 2123 | |
| 1830 | 2124 | =begin original |
| 1831 | 2125 | |
| 1832 | 2126 | C<\p{XPosixPunct}> and (under Unicode rules) C<[[:punct:]]>, match what |
| 1833 | 2127 | C<\p{PosixPunct}> matches in the ASCII range, plus what C<\p{Punct}> |
| 1834 | 2128 | matches. This is different than strictly matching according to |
| 1835 | 2129 | C<\p{Punct}>. Another way to say it is that |
| 1836 | 2130 | if Unicode rules are in effect, C<[[:punct:]]> matches all characters |
| 1837 | 2131 | that Unicode considers punctuation, plus all ASCII-range characters that |
| 1838 | 2132 | Unicode considers symbols. |
| 1839 | 2133 | |
| 1840 | 2134 | =end original |
| 1841 | 2135 | |
| 1842 | 2136 | C<\p{XPosixPunct}> と (Unicode の規則の下での) C<[[:punct:]]> は、 |
| 1843 | 2137 | ASCII の範囲で C<\p{PosixPunct}> がマッチングする物に加えて、 |
| 1844 | 2138 | C<\p{Punct}> がマッチングする物にマッチングします。 |
| 1845 | 2139 | これは C<\p{Punct}> に従って正確にマッチングする物と異なります。 |
| 1846 | 2140 | Unicode 規則が有効な場合のもう一つの言い方は、C<[[:punct:]]> は Unicode が |
| 1847 | 2141 | 句読点として扱うものに加えて、Unicode が "symbols" として扱う ASCII 範囲の |
| 1848 | 2142 | 全ての文字にマッチングします。 |
| 1849 | 2143 | |
| 1850 | 2144 | =item [6] |
| 1851 | 2145 | |
| 1852 | 2146 | =begin original |
| 1853 | 2147 | |
| 1854 | C<\p{Space | |
| 2148 | C<\p{XPerlSpace}> and C<\p{Space}> match identically starting with Perl | |
| 1855 | 2149 | v5.18. In earlier versions, these differ only in that in non-locale |
| 1856 | matching, C<\p{Space | |
| 2150 | matching, C<\p{XPerlSpace}> did not match the vertical tab, C<\cK>. | |
| 1857 | 2151 | Same for the two ASCII-only range forms. |
| 1858 | 2152 | |
| 1859 | 2153 | =end original |
| 1860 | 2154 | |
| 1861 | C<\p{Space | |
| 2155 | C<\p{XPerlSpace}> と C<\p{Space}> は、Perl v5.18 からは同じように | |
| 1862 | 2156 | マッチングします。 |
| 1863 | 2157 | 以前のバージョンでは、これらの違いは、非ロケールマッチングでは |
| 1864 | C<\p{Space | |
| 2158 | C<\p{XPerlSpace}> は垂直タブ C<\cK> にもマッチングしないということだけです。 | |
| 1865 | 2159 | 二つの ASCII のみの範囲の形式では同じです。 |
| 1866 | 2160 | |
| 2161 | =item [7] | |
| 2162 | ||
| 2163 | =begin original | |
| 2164 | ||
| 2165 | Unlike C<[[:digit:]]> which matches digits in many writing systems, such | |
| 2166 | as Thai and Devanagari, there are currently only two sets of hexadecimal | |
| 2167 | digits, and it is unlikely that more will be added. This is because you | |
| 2168 | not only need the ten digits, but also the six C<[A-F]> (and C<[a-f]>) | |
| 2169 | to correspond. That means only the Latin script is suitable for these, | |
| 2170 | and Unicode has only two sets of these, the familiar ASCII set, and the | |
| 2171 | fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO). | |
| 2172 | ||
| 2173 | =end original | |
| 2174 | ||
| 2175 | タイ文字やデバナーガリ文字のように多くの書記体系の数字にマッチングする | |
| 2176 | C<[[:digit:]]> と異なり、16 進数の二つの集合だけで、これ以上追加されることは | |
| 2177 | おそらくありません。 | |
| 2178 | これは、対応するのに 10 の数字だけでなく、6 個の C<[A-F]> (および C<[a-f]>) も | |
| 2179 | 必要だからです。 | |
| 2180 | これは、Latin 用字のみがこれらに適合していて、 | |
| 2181 | Unicode はこれらの二つの集合、つまり慣れ親しんだ | |
| 2182 | ASCII 集合と、U+FF10 (FULLWIDTH DIGIT ZERO) から始まる全角形式のみを | |
| 2183 | 持つということです。 | |
| 2184 | ||
| 1867 | 2185 | =back |
| 1868 | 2186 | |
| 1869 | 2187 | =begin original |
| 1870 | 2188 | |
| 1871 | 2189 | There are various other synonyms that can be used besides the names |
| 1872 | listed in the table. For example, C<\p{PosixAlpha}> can be written as | |
| 2190 | listed in the table. For example, C<\p{XPosixAlpha}> can be written as | |
| 1873 | 2191 | C<\p{Alpha}>. All are listed in |
| 1874 | L<perluniprops/Properties accessible through \p{} and \P{}> | |
| 2192 | L<perluniprops/Properties accessible through \p{} and \P{}>. | |
| 1875 | plus all characters matched by each ASCII-range property. | |
| 1876 | 2193 | |
| 1877 | 2194 | =end original |
| 1878 | 2195 | |
| 1879 | 2196 | 表に挙げられている名前以外にも様々なその他の同義語が使えます。 |
| 1880 | 例えば、C<\p{PosixAlpha}> は C<\p{Alpha}> と書けます。 | |
| 2197 | 例えば、C<\p{XPosixAlpha}> は C<\p{Alpha}> と書けます。 | |
| 1881 | 全ての一覧 | |
| 2198 | 全ての一覧は | |
| 1882 | ||
| 2199 | L<perluniprops/Properties accessible through \p{} and \P{}> に | |
| 1883 | 2200 | あります。 |
| 1884 | 2201 | |
| 1885 | 2202 | =begin original |
| 1886 | 2203 | |
| 1887 | 2204 | Both the C<\p> counterparts always assume Unicode rules are in effect. |
| 1888 | 2205 | On ASCII platforms, this means they assume that the code points from 128 |
| 1889 | 2206 | to 255 are Latin-1, and that means that using them under locale rules is |
| 1890 | 2207 | unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the |
| 1891 | 2208 | POSIX character classes are useful under locale rules. They are |
| 1892 | 2209 | affected by the actual rules in effect, as follows: |
| 1893 | 2210 | |
| 1894 | 2211 | =end original |
| 1895 | 2212 | |
| 1896 | 2213 | C<\p> に対応するものの両方は常に Unicode の規則が有効であることを仮定します。 |
| 1897 | 2214 | これは、ASCII プラットフォームでは、128 から 255 の符号位置は |
| 1898 | 2215 | Latin-1 であることを仮定するということで、ロケールの規則の下で |
| 1899 | 2216 | これらを使うということは、ロケールが Latin-1 か UTF-8 であることが |
| 1900 | 2217 | 補償されていない限り賢明ではないということです。 |
| 1901 | 2218 | 一方、POSIX 文字クラスはロケールの規則の下で有用です。 |
| 1902 | 2219 | これらは次のように、実際に有効な規則に影響を受けます: |
| 1903 | 2220 | |
| 1904 | 2221 | =over |
| 1905 | 2222 | |
| 1906 | 2223 | =item If the C</a> modifier, is in effect ... |
| 1907 | 2224 | |
| 1908 | 2225 | (C</a> が有効なら...) |
| 1909 | 2226 | |
| 1910 | 2227 | =begin original |
| 1911 | 2228 | |
| 1912 | 2229 | Each of the POSIX classes matches exactly the same as their ASCII-range |
| 1913 | 2230 | counterparts. |
| 1914 | 2231 | |
| 1915 | 2232 | =end original |
| 1916 | 2233 | |
| 1917 | 2234 | それぞれの POSIX クラスは ASCII の範囲で対応する正確に同じものに |
| 1918 | 2235 | マッチングします。 |
| 1919 | 2236 | |
| 1920 | 2237 | =item otherwise ... |
| 1921 | 2238 | |
| 1922 | 2239 | (さもなければ ...) |
| 1923 | 2240 | |
| 1924 | 2241 | =over |
| 1925 | 2242 | |
| 1926 | 2243 | =item For code points above 255 ... |
| 1927 | 2244 | |
| 1928 | 2245 | (256 以上の符号位置では ...) |
| 1929 | 2246 | |
| 1930 | 2247 | =begin original |
| 1931 | 2248 | |
| 1932 | 2249 | The POSIX class matches the same as its Full-range counterpart. |
| 1933 | 2250 | |
| 1934 | 2251 | =end original |
| 1935 | 2252 | |
| 1936 | 2253 | POSIX クラスはその Full の範囲で対応する同じものにマッチングします。 |
| 1937 | 2254 | |
| 1938 | 2255 | =item For code points below 256 ... |
| 1939 | 2256 | |
| 1940 | 2257 | (255 以下の符号位置では ...) |
| 1941 | 2258 | |
| 1942 | 2259 | =over |
| 1943 | 2260 | |
| 1944 | 2261 | =item if locale rules are in effect ... |
| 1945 | 2262 | |
| 1946 | 2263 | (ロケール規則が有効なら ...) |
| 1947 | 2264 | |
| 1948 | 2265 | =begin original |
| 1949 | 2266 | |
| 1950 | The POSIX class matches according to the locale, except | |
| 2267 | The POSIX class matches according to the locale, except: | |
| 1951 | ||
| 2269 | =end original | |
| 2270 | ||
| 2271 | POSIX クラスはロケールに従ってマッチングします; 例外は: | |
| 2272 | ||
| 2273 | =over | |
| 2274 | ||
| 2275 | =item C<word> | |
| 2276 | ||
| 2277 | =begin original | |
| 2278 | ||
| 2279 | also includes the platform's native underscore character, no matter what | |
| 1952 | 2280 | the locale is. |
| 1953 | 2281 | |
| 1954 | 2282 | =end original |
| 1955 | 2283 | |
| 1956 | ||
| 2284 | それに加えて、ロケールが何かに関わらず、プラットフォームのネイティブな | |
| 1957 | except that | |
| 1958 | C<word> はロケールが何かに関わらず、プラットフォームのネイティブな | |
| 1959 | 2285 | 下線文字を使います。 |
| 1960 | 2286 | |
| 1961 | =item | |
| 2287 | =item C<ascii> | |
| 1962 | 2288 | |
| 1963 | ||
| 2289 | =begin original | |
| 1964 | 2290 | |
| 2291 | on platforms that don't have the POSIX C<ascii> extension, this matches | |
| 2292 | just the platform's native ASCII-range characters. | |
| 2293 | ||
| 2294 | =end original | |
| 2295 | ||
| 2296 | POSIX C<ascii> 拡張を持たないプラットフォームでは、 | |
| 2297 | これは単にプラットフォームのネイティブな ASCII の範囲の文字に | |
| 2298 | マッチングします。 | |
| 2299 | ||
| 2300 | =item C<blank> | |
| 2301 | ||
| 1965 | 2302 | =begin original |
| 1966 | 2303 | |
| 2304 | on platforms that don't have the POSIX C<blank> extension, this matches | |
| 2305 | just the platform's native tab and space characters. | |
| 2306 | ||
| 2307 | =end original | |
| 2308 | ||
| 2309 | on platforms that don't have the | |
| 2310 | POSIX 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 | ||
| 1967 | 2322 | The POSIX class matches the same as the Full-range counterpart. |
| 1968 | 2323 | |
| 1969 | 2324 | =end original |
| 1970 | 2325 | |
| 1971 | 2326 | POSIX クラスは Full の範囲の対応する同じものにマッチングします。 |
| 1972 | 2327 | |
| 1973 | 2328 | =item otherwise ... |
| 1974 | 2329 | |
| 1975 | 2330 | (さもなければ ...) |
| 1976 | 2331 | |
| 1977 | 2332 | =begin original |
| 1978 | 2333 | |
| 1979 | 2334 | The POSIX class matches the same as the ASCII range counterpart. |
| 1980 | 2335 | |
| 1981 | 2336 | =end original |
| 1982 | 2337 | |
| 1983 | 2338 | POSIX クラスは ASCII の範囲の同じものにマッチングします。 |
| 1984 | 2339 | |
| 1985 | 2340 | =back |
| 1986 | 2341 | |
| 1987 | 2342 | =back |
| 1988 | 2343 | |
| 1989 | 2344 | =back |
| 1990 | 2345 | |
| 1991 | 2346 | =begin original |
| 1992 | 2347 | |
| 1993 | 2348 | Which rules apply are determined as described in |
| 1994 | 2349 | L<perlre/Which character set modifier is in effect?>. |
| 1995 | 2350 | |
| 1996 | 2351 | =end original |
| 1997 | 2352 | |
| 1998 | 2353 | どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で |
| 1999 | 2354 | 記述されている方法で決定されます。 |
| 2000 | 2355 | |
| 2001 | =begin original | |
| 2002 | ||
| 2003 | It is proposed to change this behavior in a future release of Perl so that | |
| 2004 | whether or not Unicode rules are in effect would not change the | |
| 2005 | behavior: Outside of locale, the POSIX classes | |
| 2006 | would behave like their ASCII-range counterparts. If you wish to | |
| 2007 | comment on this proposal, send email to C<perl5-porters@perl.org>. | |
| 2008 | ||
| 2009 | =end original | |
| 2010 | ||
| 2011 | Perl の将来のバージョンではこの振る舞いを変えることが提案されています; | |
| 2012 | Unicode の規則が有効かどうかは振る舞いを変えません: | |
| 2013 | ロケールの外側では、 | |
| 2014 | POSIX クラスはその ASCII の範囲の対応するものと同様に振る舞います。 | |
| 2015 | この提案にコメントしたいなら、C<perl5-porters@perl.org> にメールを | |
| 2016 | 送ってください。 | |
| 2017 | ||
| 2018 | 2356 | =head4 Negation of POSIX character classes |
| 2019 | 2357 | X<character class, negation> |
| 2020 | 2358 | |
| 2021 | 2359 | (POSIX 文字クラスの否定) |
| 2022 | 2360 | |
| 2023 | 2361 | =begin original |
| 2024 | 2362 | |
| 2025 | 2363 | A Perl extension to the POSIX character class is the ability to |
| 2026 | 2364 | negate it. This is done by prefixing the class name with a caret (C<^>). |
| 2027 | 2365 | Some examples: |
| 2028 | 2366 | |
| 2029 | 2367 | =end original |
| 2030 | 2368 | |
| 2031 | 2369 | POSIX 文字クラスに対する Perl の拡張は否定の機能です。 |
| 2032 | 2370 | これはクラス名の前にキャレット (C<^>) を置くことで実現します。 |
| 2033 | 2371 | いくつかの例です: |
| 2034 | 2372 | |
| 2035 | 2373 | POSIX ASCII-range Full-range backslash |
| 2036 | 2374 | Unicode Unicode sequence |
| 2037 | 2375 | ----------------------------------------------------- |
| 2038 | 2376 | [[:^digit:]] \P{PosixDigit} \P{XPosixDigit} \D |
| 2039 | 2377 | [[:^space:]] \P{PosixSpace} \P{XPosixSpace} |
| 2040 | 2378 | \P{PerlSpace} \P{XPerlSpace} \S |
| 2041 | 2379 | [[:^word:]] \P{PerlWord} \P{XPosixWord} \W |
| 2042 | 2380 | |
| 2043 | 2381 | =begin original |
| 2044 | 2382 | |
| 2045 | 2383 | The backslash sequence can mean either ASCII- or Full-range Unicode, |
| 2046 | 2384 | depending on various factors as described in L<perlre/Which character set modifier is in effect?>. |
| 2047 | 2385 | |
| 2048 | 2386 | =end original |
| 2049 | 2387 | |
| 2050 | 2388 | 逆スラッシュシーケンスは ASCII- か Full-range Unicode のどちらかを意味します; |
| 2051 | 2389 | どちらが使われるかは L<perlre/Which character set modifier is in effect?> で |
| 2052 | 2390 | 記述されている様々な要素に依存します。 |
| 2053 | 2391 | |
| 2054 | 2392 | =head4 [= =] and [. .] |
| 2055 | 2393 | |
| 2056 | 2394 | ([= =] と [. .]) |
| 2057 | 2395 | |
| 2058 | 2396 | =begin original |
| 2059 | 2397 | |
| 2060 | 2398 | Perl recognizes the POSIX character classes C<[=class=]> and |
| 2061 | 2399 | C<[.class.]>, but does not (yet?) support them. Any attempt to use |
| 2062 | 2400 | either construct raises an exception. |
| 2063 | 2401 | |
| 2064 | 2402 | =end original |
| 2065 | 2403 | |
| 2066 | 2404 | Perl は POSIX 文字クラス C<[=class=]> と C<[.class.]> を認識しますが、 |
| 2067 | 2405 | これらには(まだ?)対応していません。 |
| 2068 | 2406 | このような構文を使おうとすると例外が発生します。 |
| 2069 | 2407 | |
| 2070 | 2408 | =head4 Examples |
| 2071 | 2409 | |
| 2072 | 2410 | (例) |
| 2073 | 2411 | |
| 2074 | 2412 | =begin original |
| 2075 | 2413 | |
| 2076 | 2414 | /[[:digit:]]/ # Matches a character that is a digit. |
| 2077 | 2415 | /[01[:lower:]]/ # Matches a character that is either a |
| 2078 | 2416 | # lowercase letter, or '0' or '1'. |
| 2079 | 2417 | /[[:digit:][:^xdigit:]]/ # Matches a character that can be anything |
| 2080 | 2418 | # except the letters 'a' to 'f' and 'A' to |
| 2081 | 2419 | # 'F'. This is because the main character |
| 2082 | 2420 | # class is composed of two POSIX character |
| 2083 | 2421 | # classes that are ORed together, one that |
| 2084 | 2422 | # matches any digit, and the other that |
| 2085 | 2423 | # matches anything that isn't a hex digit. |
| 2086 | 2424 | # The OR adds the digits, leaving only the |
| 2087 | 2425 | # letters 'a' to 'f' and 'A' to 'F' excluded. |
| 2088 | 2426 | |
| 2089 | 2427 | =end original |
| 2090 | 2428 | |
| 2091 | 2429 | /[[:digit:]]/ # 数字の文字にマッチングする。 |
| 2092 | 2430 | /[01[:lower:]]/ # 小文字、'0'、'1' のいずれかの文字に |
| 2093 | 2431 | # マッチングする。 |
| 2094 | 2432 | /[[:digit:][:^xdigit:]]/ # 'a' から 'f' と 'A' から 'F' 以外の任意の文字に |
| 2095 | 2433 | # マッチング。これはメインの文字クラスでは二つの |
| 2096 | 2434 | # POSIX 文字クラスが OR され、一つは任意の数字に |
| 2097 | 2435 | # マッチングし、もう一つは 16 進文字でない全ての |
| 2098 | 2436 | # 文字にマッチングします。OR は数字を加え、 |
| 2099 | 2437 | # 'a' から 'f' および 'A' から 'F' のみが |
| 2100 | 2438 | # 除外されて残ります。 |
| 2101 | # | |
| 2102 | 2439 | |
| 2103 | 2440 | =head3 Extended Bracketed Character Classes |
| 2104 | 2441 | X<character class> |
| 2105 | 2442 | X<set operations> |
| 2106 | 2443 | |
| 2107 | 2444 | (拡張大かっこ文字クラス) |
| 2108 | 2445 | |
| 2109 | 2446 | =begin original |
| 2110 | 2447 | |
| 2111 | 2448 | This is a fancy bracketed character class that can be used for more |
| 2112 | 2449 | readable and less error-prone classes, and to perform set operations, |
| 2113 | 2450 | such as intersection. An example is |
| 2114 | 2451 | |
| 2115 | 2452 | =end original |
| 2116 | 2453 | |
| 2117 | 2454 | これはしゃれた大かっこ文字クラスで、より読みやすく、エラーが発生しにくい |
| 2118 | 2455 | クラスや、交差などの集合演算を実行するために使用できます。 |
| 2456 | 例は: | |
| 2119 | 2457 | |
| 2120 | 2458 | /(?[ \p{Thai} & \p{Digit} ])/ |
| 2121 | 2459 | |
| 2122 | 2460 | =begin original |
| 2123 | 2461 | |
| 2124 | 2462 | This will match all the digit characters that are in the Thai script. |
| 2125 | 2463 | |
| 2126 | 2464 | =end original |
| 2127 | 2465 | |
| 2128 | 2466 | これは、タイ語スクリプト内のすべての数字と一致します。 |
| 2129 | 2467 | |
| 2130 | 2468 | =begin original |
| 2131 | 2469 | |
| 2132 | This | |
| 2470 | This feature became available in Perl 5.18, as experimental; accepted in | |
| 2133 | ||
| 2471 | 5.36. | |
| 2134 | use it will raise a warning, unless disabled via | |
| 2135 | 2472 | |
| 2136 | 2473 | =end original |
| 2137 | 2474 | |
| 2138 | こ | |
| 2475 | この機能は Perl 5.18 で実験的に利用可能になりました; | |
| 2139 | ||
| 2476 | 5.36 で受け入れられました。 | |
| 2140 | これを使用しようとすると、次のようにして無効にしない限り、警告が表示されます: | |
| 2141 | 2477 | |
| 2142 | no warnings "experimental::regex_sets"; | |
| 2143 | ||
| 2144 | 2478 | =begin original |
| 2145 | 2479 | |
| 2146 | ||
| 2480 | The rules used by L<C<use re 'strict>|re/'strict' mode> apply to this | |
| 2147 | ||
| 2481 | construct. | |
| 2148 | 2482 | |
| 2149 | 2483 | =end original |
| 2150 | 2484 | |
| 2151 | この | |
| 2485 | L<C<use re 'strict>|re/'strict' mode> で使われる規則はこの構文に | |
| 2152 | ||
| 2486 | 適用されます。 | |
| 2153 | 2487 | |
| 2154 | 2488 | =begin original |
| 2155 | 2489 | |
| 2156 | 2490 | We can extend the example above: |
| 2157 | 2491 | |
| 2158 | 2492 | =end original |
| 2159 | 2493 | |
| 2160 | 2494 | 上記の例を拡張できます: |
| 2161 | 2495 | |
| 2162 | 2496 | /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])/ |
| 2163 | 2497 | |
| 2164 | 2498 | =begin original |
| 2165 | 2499 | |
| 2166 | 2500 | This matches digits that are in either the Thai or Laotian scripts. |
| 2167 | 2501 | |
| 2168 | 2502 | =end original |
| 2169 | 2503 | |
| 2170 | 2504 | これはタイ語またはラオス語のいずれかの数字と一致します。 |
| 2171 | 2505 | |
| 2172 | 2506 | =begin original |
| 2173 | 2507 | |
| 2174 | 2508 | Notice the white space in these examples. This construct always has |
| 2175 | the C<E<sol>x> modifier turned on. | |
| 2509 | the C<E<sol>xx> modifier turned on within it. | |
| 2176 | 2510 | |
| 2177 | 2511 | =end original |
| 2178 | 2512 | |
| 2179 | 2513 | これらの例の中の空白に注意してください。 |
| 2180 | この構文では、常に C<E<sol>x> 修飾子がオンになっています。 | |
| 2514 | この構文では、その中では常に C<E<sol>xx> 修飾子がオンになっています。 | |
| 2181 | 2515 | |
| 2182 | 2516 | =begin original |
| 2183 | 2517 | |
| 2184 | 2518 | The available binary operators are: |
| 2185 | 2519 | |
| 2186 | 2520 | =end original |
| 2187 | 2521 | |
| 2188 | 2522 | 使用可能な 2 項演算子は次のとおりです: |
| 2189 | 2523 | |
| 2190 | 2524 | & intersection |
| 2191 | 2525 | + union |
| 2192 | 2526 | | another name for '+', hence means union |
| 2193 | 2527 | - subtraction (the result matches the set consisting of those |
| 2194 | 2528 | code points matched by the first operand, excluding any that |
| 2195 | 2529 | are also matched by the second operand) |
| 2196 | 2530 | ^ symmetric difference (the union minus the intersection). This |
| 2197 | 2531 | is like an exclusive or, in that the result is the set of code |
| 2198 | 2532 | points that are matched by either, but not both, of the |
| 2199 | 2533 | operands. |
| 2200 | 2534 | |
| 2201 | 2535 | =begin original |
| 2202 | 2536 | |
| 2203 | 2537 | There is one unary operator: |
| 2204 | 2538 | |
| 2205 | 2539 | =end original |
| 2206 | 2540 | |
| 2207 | 2541 | 単項演算子が一つあります。 |
| 2208 | 2542 | |
| 2209 | 2543 | ! complement |
| 2210 | 2544 | |
| 2211 | 2545 | =begin original |
| 2212 | 2546 | |
| 2213 | All the binary operators left associate | |
| 2547 | All the binary operators left associate; C<"&"> is higher precedence | |
| 2214 | ||
| 2548 | than the others, which all have equal precedence. The unary operator | |
| 2215 | ||
| 2549 | right associates, and has highest precedence. Thus this follows the | |
| 2216 | rece | |
| 2550 | normal Perl precedence rules for logical operators. Use parentheses to | |
| 2217 | ||
| 2551 | override the default precedence and associativity. | |
| 2218 | to change in future releases; you may want to parenthesize copiously to | |
| 2219 | avoid such changes affecting your code, until this feature is no longer | |
| 2220 | considered experimental. | |
| 2221 | 2552 | |
| 2222 | 2553 | =end original |
| 2223 | 2554 | |
| 2224 | すべての二項演算子は左結合で | |
| 2555 | すべての二項演算子は左結合です; C<"&"> はその他よりも高い優先順位を持ち、 | |
| 2225 | ||
| 2556 | それ以外は同等の優先順位を持ちます。 | |
| 2226 | ||
| 2557 | 単項演算子は右結合で、最も高い優先順位を持ちます。 | |
| 2227 | ||
| 2558 | 従って、これは通常の Perl の論理演算子に関する優先順位規則に従います。 | |
| 2228 | ||
| 2559 | デフォルトの優先順位と結合を上書きするにはかっこを使います。 | |
| 2229 | これは、フィールドからのフィードバックによって、 | |
| 2230 | 将来のリリースで変更される可能性があるものです; | |
| 2231 | この機能が実験的であるとみなされなくなるまで、コードにそのような変更が | |
| 2232 | 影響しないように、かっこをたくさん入れた方がよいでしょう。 | |
| 2233 | 2560 | |
| 2234 | 2561 | =begin original |
| 2235 | 2562 | |
| 2236 | 2563 | The main restriction is that everything is a metacharacter. Thus, |
| 2237 | 2564 | you cannot refer to single characters by doing something like this: |
| 2238 | 2565 | |
| 2239 | 2566 | =end original |
| 2240 | 2567 | |
| 2241 | 2568 | 主な制限は、すべてがメタ文字であるということです。 |
| 2242 | 2569 | したがって、以下のようにして単一文字を参照することはできません: |
| 2243 | 2570 | |
| 2244 | 2571 | /(?[ a + b ])/ # Syntax error! |
| 2245 | 2572 | |
| 2246 | 2573 | =begin original |
| 2247 | 2574 | |
| 2248 | 2575 | The easiest way to specify an individual typable character is to enclose |
| 2249 | 2576 | it in brackets: |
| 2250 | 2577 | |
| 2251 | 2578 | =end original |
| 2252 | 2579 | |
| 2253 | 2580 | タイプ可能な個々の文字を指定する最も簡単な方法は、次のように |
| 2254 | 2581 | かっこで囲むことです: |
| 2255 | 2582 | |
| 2256 | 2583 | /(?[ [a] + [b] ])/ |
| 2257 | 2584 | |
| 2258 | 2585 | =begin original |
| 2259 | 2586 | |
| 2260 | 2587 | (This is the same thing as C<[ab]>.) You could also have said the |
| 2261 | 2588 | equivalent: |
| 2262 | 2589 | |
| 2263 | 2590 | =end original |
| 2264 | 2591 | |
| 2265 | 2592 | (これはC<[ab]>と同じことです)。 |
| 2266 | 2593 | 同じことを言うこともできます: |
| 2267 | 2594 | |
| 2268 | 2595 | /(?[[ a b ]])/ |
| 2269 | 2596 | |
| 2270 | 2597 | =begin original |
| 2271 | 2598 | |
| 2272 | (You can, of course, specify single characters by using, C<\x{ | |
| 2599 | (You can, of course, specify single characters by using, C<\x{...}>, | |
| 2273 | C<\N{ | |
| 2600 | C<\N{...}>, etc.) | |
| 2274 | 2601 | |
| 2275 | 2602 | =end original |
| 2276 | 2603 | |
| 2277 | (もちろん、C<\x{ | |
| 2604 | (もちろん、C<\x{...}> や C<\N{...}> などを使用して 1 文字を | |
| 2278 | 2605 | 指定することもできます。) |
| 2279 | 2606 | |
| 2280 | 2607 | =begin original |
| 2281 | 2608 | |
| 2282 | 2609 | This last example shows the use of this construct to specify an ordinary |
| 2283 | 2610 | bracketed character class without additional set operations. Note the |
| 2284 | white space within it | |
| 2611 | white space within it. This is allowed because C<E<sol>xx> is | |
| 2285 | ||
| 2612 | automatically turned on within this construct. | |
| 2286 | 2613 | |
| 2287 | 2614 | =end original |
| 2288 | 2615 | |
| 2289 | 2616 | この最後の例では、この構文を使用して、追加の集合操作なしで |
| 2290 | 2617 | 通常の大かっこ文字クラスを指定する方法を示しています。 |
| 2291 | この中に空白があることに注意してください | |
| 2618 | この中に空白があることに注意してください。 | |
| 2292 | C<E<sol>x> は、 | |
| 2619 | C<E<sol>xx> は、この構文の内側で自動的に有効になるのでこれが許されます。 | |
| 2293 | コメントを含めることはできません。 | |
| 2294 | したがって: | |
| 2295 | 2620 | |
| 2296 | (?[ [#] ]) | |
| 2297 | ||
| 2298 | 2621 | =begin original |
| 2299 | 2622 | |
| 2300 | matches the literal character "#". To specify a literal white space character, | |
| 2301 | you can escape it with a backslash, like: | |
| 2302 | ||
| 2303 | =end original | |
| 2304 | ||
| 2305 | は、リテラル文字 "#" にマッチングします。 | |
| 2306 | リテラル空白文字を指定するには、次のように逆スラッシュでエスケープします: | |
| 2307 | ||
| 2308 | /(?[ [ a e i o u \ ] ])/ | |
| 2309 | ||
| 2310 | =begin original | |
| 2311 | ||
| 2312 | This matches the English vowels plus the SPACE character. | |
| 2313 | 2623 | All the other escapes accepted by normal bracketed character classes are |
| 2314 | accepted here as well | |
| 2624 | accepted here as well. | |
| 2315 | in normal classes are fatal errors here. | |
| 2316 | 2625 | |
| 2317 | 2626 | =end original |
| 2318 | 2627 | |
| 2319 | これは英語の母音と SPACE 文字に一致します。 | |
| 2320 | 2628 | 通常の大かっこ文字クラスで受け入れられる他のエスケープは |
| 2321 | すべてここでも受け入れられます | |
| 2629 | すべてここでも受け入れられます。 | |
| 2322 | 認識されないエスケープはここでは致命的なエラーです。 | |
| 2323 | 2630 | |
| 2324 | 2631 | =begin original |
| 2325 | 2632 | |
| 2326 | ||
| 2633 | Because this construct compiles under | |
| 2327 | ||
| 2634 | L<C<use re 'strict>|re/'strict' mode>, unrecognized escapes that | |
| 2635 | generate warnings in normal classes are fatal errors here, as well as | |
| 2636 | all other warnings from these class elements, as well as some | |
| 2637 | practices that don't currently warn outside C<re 'strict'>. For example | |
| 2638 | you cannot say | |
| 2328 | 2639 | |
| 2329 | 2640 | =end original |
| 2330 | 2641 | |
| 2331 | こ | |
| 2642 | この構文は L<C<use re 'strict>|re/'strict' mode> の下でコンパイルされるので、 | |
| 2332 | ||
| 2643 | 通常のクラスで警告を生成する | |
| 2644 | 認識されないエスケープはここでは致命的なエラーです; | |
| 2645 | これらのクラス要素からのその他すべての警告も同様で、 | |
| 2646 | C<re 'strict'> の外側では、現在警告していないいくつかのプラクティスも | |
| 2647 | 同様です。 | |
| 2333 | 2648 | 例えば次のようにはできません: |
| 2334 | 2649 | |
| 2335 | 2650 | /(?[ [ \xF ] ])/ # Syntax error! |
| 2336 | 2651 | |
| 2337 | 2652 | =begin original |
| 2338 | 2653 | |
| 2339 | 2654 | You have to have two hex digits after a braceless C<\x> (use a leading |
| 2340 | 2655 | zero to make two). These restrictions are to lower the incidence of |
| 2341 | 2656 | typos causing the class to not match what you thought it would. |
| 2342 | 2657 | |
| 2343 | 2658 | =end original |
| 2344 | 2659 | |
| 2345 | 2660 | 中かっこのない C<\x> の後には 2 桁の 16 進数が必要です(2 桁にするには |
| 2346 | 2661 | 先頭の 0 を使用します)。 |
| 2347 | 2662 | これらの制限は、クラスが想定したものと一致しない原因となる |
| 2348 | 2663 | タイプミスの発生を減らすためです。 |
| 2349 | 2664 | |
| 2350 | 2665 | =begin original |
| 2351 | 2666 | |
| 2667 | If a regular bracketed character class contains a C<\p{}> or C<\P{}> and | |
| 2668 | is matched against a non-Unicode code point, a warning may be | |
| 2669 | raised, as the result is not Unicode-defined. No such warning will come | |
| 2670 | when using this extended form. | |
| 2671 | ||
| 2672 | =end original | |
| 2673 | ||
| 2674 | 通常の大かっこ文字クラスに C<\p{}> や C<\P{}> が含まれていて、 | |
| 2675 | 非 Unicode 符号位置に対してマッチングした場合、 | |
| 2676 | 結果は Unicode で定義されていないので、警告が発生します。 | |
| 2677 | このような警告は、拡張形式を使った場合は発生しません。 | |
| 2678 | ||
| 2679 | =begin original | |
| 2680 | ||
| 2352 | 2681 | The final difference between regular bracketed character classes and |
| 2353 | 2682 | these, is that it is not possible to get these to match a |
| 2354 | 2683 | multi-character fold. Thus, |
| 2355 | 2684 | |
| 2356 | 2685 | =end original |
| 2357 | 2686 | |
| 2358 | 2687 | 通常の大かっこ文字クラスとこれらのクラスの最後の違いは、 |
| 2359 | 2688 | これらを複数文字畳み込みにマッチングさせることができないということです。 |
| 2360 | 2689 | 従って: |
| 2361 | 2690 | |
| 2362 | 2691 | /(?[ [\xDF] ])/iu |
| 2363 | 2692 | |
| 2364 | 2693 | =begin original |
| 2365 | 2694 | |
| 2366 | 2695 | does not match the string C<ss>. |
| 2367 | 2696 | |
| 2368 | 2697 | =end original |
| 2369 | 2698 | |
| 2370 | 2699 | は文字列 C<ss> と一致しません。 |
| 2371 | 2700 | |
| 2372 | 2701 | =begin original |
| 2373 | 2702 | |
| 2374 | 2703 | You don't have to enclose POSIX class names inside double brackets, |
| 2375 | 2704 | hence both of the following work: |
| 2376 | 2705 | |
| 2377 | 2706 | =end original |
| 2378 | 2707 | |
| 2379 | 2708 | POSIX クラス名を二重かっこで囲む必要はありません; |
| 2380 | 2709 | そのため、以下の両方とも動作します: |
| 2381 | 2710 | |
| 2382 | 2711 | /(?[ [:word:] - [:lower:] ])/ |
| 2383 | 2712 | /(?[ [[:word:]] - [[:lower:]] ])/ |
| 2384 | 2713 | |
| 2385 | 2714 | =begin original |
| 2386 | 2715 | |
| 2387 | 2716 | Any contained POSIX character classes, including things like C<\w> and C<\D> |
| 2388 | 2717 | respect the C<E<sol>a> (and C<E<sol>aa>) modifiers. |
| 2389 | 2718 | |
| 2390 | 2719 | =end original |
| 2391 | 2720 | |
| 2392 | 2721 | C<\w> や C<\D> などの POSIX 文字クラスは、C<E<sol>a> |
| 2393 | 2722 | (および C<E<sol>aa> )修飾子を尊重します。 |
| 2394 | 2723 | |
| 2395 | 2724 | =begin original |
| 2396 | 2725 | |
| 2397 | C<< (?[ ]) >> is a regex-compile-time construct. Any attempt | |
| 2726 | Note that C<< (?[ ]) >> is a regex-compile-time construct. Any attempt | |
| 2398 | something which isn't knowable at the time the containing regular | |
| 2727 | to use something which isn't knowable at the time the containing regular | |
| 2399 | 2728 | expression is compiled is a fatal error. In practice, this means |
| 2400 | just three limit | |
| 2729 | just three limitations: | |
| 2401 | 2730 | |
| 2402 | 2731 | =end original |
| 2403 | 2732 | |
| 2404 | C<< (?[ ]) >> は コンパイル時正規表現構文で | |
| 2733 | C<< (?[ ]) >> は コンパイル時正規表現構文であることに注意してください。 | |
| 2405 | 2734 | 正規表現を含むコンパイル時に未知のものを使用しようとすると、 |
| 2406 | 2735 | 致命的なエラーになります。 |
| 2407 | 2736 | 実際には、これは三つの制限を意味します: |
| 2408 | 2737 | |
| 2409 | 2738 | =over 4 |
| 2410 | 2739 | |
| 2411 | 2740 | =item 1 |
| 2412 | 2741 | |
| 2413 | 2742 | =begin original |
| 2414 | 2743 | |
| 2415 | ||
| 2744 | When compiled within the scope of C<use locale> (or the C<E<sol>l> regex | |
| 2416 | ||
| 2745 | modifier), this construct assumes that the execution-time locale will be | |
| 2746 | a UTF-8 one, and the generated pattern always uses Unicode rules. What | |
| 2747 | gets matched or not thus isn't dependent on the actual runtime locale, so | |
| 2748 | tainting is not enabled. But a C<locale> category warning is raised | |
| 2749 | if the runtime locale turns out to not be UTF-8. | |
| 2417 | 2750 | |
| 2418 | 2751 | =end original |
| 2419 | 2752 | |
| 2420 | ||
| 2753 | C<use locale> (または C<E<sol>l> 正規表現修飾子)の | |
| 2421 | スコープ内では | |
| 2754 | スコープ内でコンパイルされると、この構文は実行時ロケールが | |
| 2755 | UTF-8 のものであることを仮定し、 | |
| 2756 | 生成されたパターンは常に Unicode の規則を使います。 | |
| 2757 | 従ってマッチングするかどうかは実際の実行時ロケールには関係なく、 | |
| 2758 | 汚染チェックモードは有効になりません。 | |
| 2759 | しかし、実行時ロケールが UTF-8 以外になると、 | |
| 2760 | C<locale> カテゴリの警告が発生します。 | |
| 2422 | 2761 | |
| 2423 | 2762 | =item 2 |
| 2424 | 2763 | |
| 2425 | 2764 | =begin original |
| 2426 | 2765 | |
| 2427 | 2766 | Any |
| 2428 | 2767 | L<user-defined property|perlunicode/"User-Defined Character Properties"> |
| 2429 | 2768 | used must be already defined by the time the regular expression is |
| 2430 | 2769 | compiled (but note that this construct can be used instead of such |
| 2431 | 2770 | properties). |
| 2432 | 2771 | |
| 2433 | 2772 | =end original |
| 2434 | 2773 | |
| 2435 | 2774 | 使用される |
| 2436 | 2775 | L<ユーザー定義特性|perlunicode/"User-Defined Character Properties"> は、 |
| 2437 | 2776 | 正規表現がコンパイルされるときにすでに定義されている必要があります |
| 2438 | 2777 | (ただし、このような特性の代わりにこの構文を使用することもできます)。 |
| 2439 | 2778 | |
| 2440 | 2779 | =item 3 |
| 2441 | 2780 | |
| 2442 | 2781 | =begin original |
| 2443 | 2782 | |
| 2444 | 2783 | A regular expression that otherwise would compile |
| 2445 | 2784 | using C<E<sol>d> rules, and which uses this construct will instead |
| 2446 | 2785 | use C<E<sol>u>. Thus this construct tells Perl that you don't want |
| 2447 | 2786 | C<E<sol>d> rules for the entire regular expression containing it. |
| 2448 | 2787 | |
| 2449 | 2788 | =end original |
| 2450 | 2789 | |
| 2451 | 2790 | C<E<sol>d> 規則を使用してコンパイルされ、この構文を使用する正規表現は、 |
| 2452 | 2791 | 代わりに C<E<sol>u> を使用します。 |
| 2453 | 2792 | したがって、この構文は、C<E<sol>d> 規則が含まれている |
| 2454 | 2793 | 正規表現全体に対して C<E<sol>d> 規則が必要ないことを Perl に通知します。 |
| 2455 | 2794 | |
| 2456 | 2795 | =back |
| 2457 | 2796 | |
| 2458 | 2797 | =begin original |
| 2459 | 2798 | |
| 2460 | The C<E<sol>x> processing within this class is an extended form. | |
| 2461 | Besides the characters that are considered white space in normal C</x> | |
| 2462 | processing, there are 5 others, recommended by the Unicode standard: | |
| 2463 | ||
| 2464 | =end original | |
| 2465 | ||
| 2466 | このクラス内の C<E<sol>x> 処理は拡張された形式です。 | |
| 2467 | 通常の C</x> 処理で空白と見なされる文字の他に、Unicode 標準で | |
| 2468 | 推奨されている五つの文字があります: | |
| 2469 | ||
| 2470 | U+0085 NEXT LINE | |
| 2471 | U+200E LEFT-TO-RIGHT MARK | |
| 2472 | U+200F RIGHT-TO-LEFT MARK | |
| 2473 | U+2028 LINE SEPARATOR | |
| 2474 | U+2029 PARAGRAPH SEPARATOR | |
| 2475 | ||
| 2476 | =begin original | |
| 2477 | ||
| 2478 | 2799 | Note that skipping white space applies only to the interior of this |
| 2479 | 2800 | construct. There must not be any space between any of the characters |
| 2480 | 2801 | that form the initial C<(?[>. Nor may there be space between the |
| 2481 | 2802 | closing C<])> characters. |
| 2482 | 2803 | |
| 2483 | 2804 | =end original |
| 2484 | 2805 | |
| 2485 | 2806 | 空白のスキップは、この構造体の内部にのみ適用されることに注意してください。 |
| 2486 | 2807 | 最初の C<(?[> を形成する文字の間に空白を入れることはできません。 |
| 2487 | 2808 | また、終わりの C<])> 文字の間に空白を入れることもできません。 |
| 2488 | 2809 | |
| 2489 | 2810 | =begin original |
| 2490 | 2811 | |
| 2491 | Just as in all regular expressions, the pattern can | |
| 2812 | Just as in all regular expressions, the pattern can be built up by | |
| 2492 | 2813 | including variables that are interpolated at regex compilation time. |
| 2493 | ||
| 2814 | But currently each such sub-component should be an already-compiled | |
| 2494 | exa | |
| 2815 | extended bracketed character class. | |
| 2495 | 2816 | |
| 2496 | 2817 | =end original |
| 2497 | 2818 | |
| 2498 | 2819 | すべての正規表現と同様に、正規表現コンパイル時に補完される変数を |
| 2499 | 2820 | 含めることでパターンを構築できます。 |
| 2500 | ||
| 2821 | しかし、現在の所、このような部分要素のそれぞれは | |
| 2501 | ||
| 2822 | すでにコンパイルされた拡張大かっこ文字クラスであるべきです。 | |
| 2502 | 2823 | |
| 2503 | my $thai_or_lao = | |
| 2824 | my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/; | |
| 2504 | 2825 | ... |
| 2505 | 2826 | qr/(?[ \p{Digit} & $thai_or_lao ])/; |
| 2506 | 2827 | |
| 2507 | 2828 | =begin original |
| 2508 | 2829 | |
| 2509 | compile | |
| 2830 | If you interpolate something else, the pattern may still compile (or it | |
| 2831 | may die), but if it compiles, it very well may not behave as you would | |
| 2832 | expect: | |
| 2510 | 2833 | |
| 2511 | 2834 | =end original |
| 2512 | 2835 | |
| 2513 | ||
| 2836 | 何か違うものを変数展開すると、パターンはやはりコンパイルされます | |
| 2837 | (あるいは die します)が、コンパイルされると、想像しているものと | |
| 2838 | かなり違う振る舞いになるかもしれません: | |
| 2514 | 2839 | |
| 2515 | | |
| 2840 | my $thai_or_lao = '\p{Thai} + \p{Lao}'; | |
| 2841 | qr/(?[ \p{Digit} & $thai_or_lao ])/; | |
| 2516 | 2842 | |
| 2517 | 2843 | =begin original |
| 2518 | 2844 | |
| 2519 | ||
| 2845 | compiles to | |
| 2520 | likely expect, as the intersection applies just to C<\p{Thai}>, | |
| 2521 | excluding the Laotian. Pitfalls like this can be avoided by | |
| 2522 | parenthesizing the component pieces: | |
| 2523 | 2846 | |
| 2524 | 2847 | =end original |
| 2525 | 2848 | |
| 2526 | ||
| 2849 | これは次のようにコンパイルされます: | |
| 2527 | なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には | |
| 2528 | 適用されないからです。 | |
| 2529 | このような落とし穴は、コンポーネントをかっこで囲むことで回避できます: | |
| 2530 | 2850 | |
| 2531 | | |
| 2851 | qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/; | |
| 2532 | 2852 | |
| 2533 | 2853 | =begin original |
| 2534 | 2854 | |
| 2535 | ||
| 2855 | This does not have the effect that someone reading the source code | |
| 2856 | would likely expect, as the intersection applies just to C<\p{Thai}>, | |
| 2857 | excluding the Laotian. | |
| 2536 | 2858 | |
| 2537 | 2859 | =end original |
| 2538 | 2860 | |
| 2539 | ||
| 2861 | これは、ソースコードを読んでいる人が期待するような効果はありません; | |
| 2862 | なぜなら、この交差は C<\p{Thai}> だけに適用され、ラオス語には | |
| 2863 | 適用されないからです。 | |
| 2540 | 2864 | |
| 2541 | my $lower = '\p{Lower} + \p{Digit}'; | |
| 2542 | qr/(?[ \p{Greek} & $lower ])/i; | |
| 2543 | ||
| 2544 | 2865 | =begin original |
| 2545 | 2866 | |
| 2546 | matches upper case things. You can avoid surprises by making the | |
| 2547 | components into instances of this construct by compiling them: | |
| 2548 | ||
| 2549 | =end original | |
| 2550 | ||
| 2551 | これは大文字のものと一致します。 | |
| 2552 | コンポーネントをコンパイルしてこの構文の実体にすることで、 | |
| 2553 | 予期せぬ事態を避けることができます: | |
| 2554 | ||
| 2555 | my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/; | |
| 2556 | my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/; | |
| 2557 | ||
| 2558 | =begin original | |
| 2559 | ||
| 2560 | When these are embedded in another pattern, what they match does not | |
| 2561 | change, regardless of parenthesization or what modifiers are in effect | |
| 2562 | in that outer pattern. | |
| 2563 | ||
| 2564 | =end original | |
| 2565 | ||
| 2566 | これらが別のパターンに埋め込まれている場合、親子関係やその外側のパターンで | |
| 2567 | 有効な修飾子に関係なく、一致するものは変わりません。 | |
| 2568 | ||
| 2569 | =begin original | |
| 2570 | ||
| 2571 | 2867 | Due to the way that Perl parses things, your parentheses and brackets |
| 2572 | 2868 | may need to be balanced, even including comments. If you run into any |
| 2573 | examples, please s | |
| 2869 | examples, please submit them to L<https://github.com/Perl/perl5/issues>, | |
| 2574 | concrete example for this man page. | |
| 2870 | so that we can have a concrete example for this man page. | |
| 2575 | 2871 | |
| 2576 | 2872 | =end original |
| 2577 | 2873 | |
| 2578 | 2874 | Perl の構文解析方法によっては、コメントを含めてもかっこと大かっこの |
| 2579 | 2875 | バランスを取る必要がある場合があります。 |
| 2580 | もし何か例を見つけたら、 | |
| 2876 | もし何か例を見つけたら、L<https://github.com/Perl/perl5/issues> に | |
| 2877 | 登録してください; | |
| 2581 | 2878 | そうすれば、この man ページの具体的な例を得ることができます。 |
| 2582 | ||
| 2583 | =begin original | |
| 2584 | ||
| 2585 | We may change it so that things that remain legal uses in normal bracketed | |
| 2586 | character classes might become illegal within this experimental | |
| 2587 | construct. One proposal, for example, is to forbid adjacent uses of the | |
| 2588 | same character, as in C<(?[ [aa] ])>. The motivation for such a change | |
| 2589 | is that this usage is likely a typo, as the second "a" adds nothing. | |
| 2590 | ||
| 2591 | =end original | |
| 2592 | ||
| 2593 | たとえば、C<(?[ [aa] ])> のように、同じ文字を隣接して使用すること | |
| 2594 | を禁止することが提案されています。 | |
| 2595 | このような変更の動機は、2 番目の "a" は何も追加しないので、この使用は | |
| 2596 | タイプミスである可能性が高いということです。 | |
| 2597 | 2879 | |
| 2598 | 2880 | =begin meta |
| 2599 | 2881 | |
| 2600 | 2882 | Translate: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.1-) |
| 2601 | 2883 | Status: completed |
| 2602 | 2884 | |
| 2603 | 2885 | =end meta |