re-0.08 >
0.09
との差分
re 0.09 と 0.08 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | re - Perl pragma to alter regular expression behaviour |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | re - 正規表現の振る舞いを変えるための Perl プラグマ |
13 | 13 | |
14 | 14 | =head1 SYNOPSIS |
15 | 15 | |
16 | 16 | =begin original |
17 | 17 | |
18 | 18 | use re 'taint'; |
19 | 19 | ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here |
20 | 20 | |
21 | 21 | =end original |
22 | 22 | |
23 | 23 | use re 'taint'; |
24 | 24 | ($x) = ($^X =~ /^(.*)$/s); # $x はここで汚染されている |
25 | 25 | |
26 | 26 | =begin original |
27 | 27 | |
28 | 28 | $pat = '(?{ $foo = 1 })'; |
29 | 29 | use re 'eval'; |
30 | 30 | /foo${pat}bar/; # won't fail (when not under -T switch) |
31 | 31 | |
32 | 32 | =end original |
33 | 33 | |
34 | 34 | $pat = '(?{ $foo = 1 })'; |
35 | 35 | use re 'eval'; |
36 | 36 | /foo${pat}bar/; # 失敗しない (-T スイッチがないとき) |
37 | 37 | |
38 | 38 | =begin original |
39 | 39 | |
40 | 40 | { |
41 | 41 | no re 'taint'; # the default |
42 | 42 | ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here |
43 | 43 | |
44 | 44 | =end original |
45 | 45 | |
46 | 46 | { |
47 | 47 | no re 'taint'; # デフォルト |
48 | 48 | ($x) = ($^X =~ /^(.*)$/s); # $x はここで汚染されていない |
49 | 49 | |
50 | 50 | =begin original |
51 | 51 | |
52 | 52 | no re 'eval'; # the default |
53 | 53 | /foo${pat}bar/; # disallowed (with or without -T switch) |
54 | 54 | } |
55 | 55 | |
56 | 56 | =end original |
57 | 57 | |
58 | 58 | no re 'eval'; # デフォルト |
59 | 59 | /foo${pat}bar/; # 許されない (-T スイッチの有無に関係なく) |
60 | 60 | } |
61 | 61 | |
62 | 62 | =begin original |
63 | 63 | |
64 | 64 | use re 'debug'; # output debugging info during |
65 | 65 | /^(.*)$/s; # compile and run time |
66 | 66 | |
67 | 67 | =end original |
68 | 68 | |
69 | 69 | use re 'debug'; # コンパイル時と実行時に |
70 | 70 | /^(.*)$/s; # デバッグ情報を出力する |
71 | 71 | |
72 | 72 | =begin original |
73 | 73 | |
74 | 74 | use re 'debugcolor'; # same as 'debug', but with colored output |
75 | 75 | ... |
76 | 76 | |
77 | 77 | =end original |
78 | 78 | |
79 | 79 | use re 'debugcolor'; # 'debug' と同じだが、出力に色がつく |
80 | 80 | ... |
81 | 81 | |
82 | 82 | =begin original |
83 | 83 | |
84 | 84 | use re qw(Debug All); # Finer tuned debugging options. |
85 | 85 | use re qw(Debug More); |
86 | 86 | no re qw(Debug ALL); # Turn of all re debugging in this scope |
87 | 87 | |
88 | 88 | =end original |
89 | 89 | |
90 | 90 | use re qw(Debug All); # より細かいデバッグオプション |
91 | 91 | use re qw(Debug More); |
92 | 92 | no re qw(Debug ALL); # このスコープ内で全ての re デバッグを有効化 |
93 | 93 | |
94 | 94 | use re qw(is_regexp regexp_pattern); # import utility functions |
95 | 95 | my ($pat,$mods)=regexp_pattern(qr/foo/i); |
96 | 96 | if (is_regexp($obj)) { |
97 | 97 | print "Got regexp: ", |
98 | 98 | scalar regexp_pattern($obj); # just as perl would stringify it |
99 | 99 | } # but no hassle with blessed re's. |
100 | 100 | |
101 | 101 | =begin original |
102 | 102 | |
103 | 103 | (We use $^X in these examples because it's tainted by default.) |
104 | 104 | |
105 | 105 | =end original |
106 | 106 | |
107 | 107 | (これらの例では、デフォルトで汚染されているので $^X を使っています。) |
108 | 108 | |
109 | 109 | =head1 DESCRIPTION |
110 | 110 | |
111 | 111 | =head2 'taint' mode |
112 | 112 | |
113 | 113 | ('taint' モード) |
114 | 114 | |
115 | 115 | =begin original |
116 | 116 | |
117 | 117 | When C<use re 'taint'> is in effect, and a tainted string is the target |
118 | 118 | of a regex, the regex memories (or values returned by the m// operator |
119 | 119 | in list context) are tainted. This feature is useful when regex operations |
120 | 120 | on tainted data aren't meant to extract safe substrings, but to perform |
121 | 121 | other transformations. |
122 | 122 | |
123 | 123 | =end original |
124 | 124 | |
125 | 125 | C<use re 'taint'> が有効で、汚染された文字列が正規表現の |
126 | 126 | ターゲットであるとき、正規表現のメモリ(もしくはリストコンテキストで |
127 | 127 | m// 演算子が返す値)は汚染されます。 |
128 | 128 | この機能は汚染されたデータに対する正規表現演算が安全な部分文字列を |
129 | 129 | 取り出すものでないときに便利ですが、その他の変換は働きます。 |
130 | 130 | |
131 | 131 | =head2 'eval' mode |
132 | 132 | |
133 | 133 | ('eval' モード) |
134 | 134 | |
135 | 135 | =begin original |
136 | 136 | |
137 | 137 | When C<use re 'eval'> is in effect, a regex is allowed to contain |
138 | 138 | C<(?{ ... })> zero-width assertions even if regular expression contains |
139 | 139 | variable interpolation. That is normally disallowed, since it is a |
140 | 140 | potential security risk. Note that this pragma is ignored when the regular |
141 | 141 | expression is obtained from tainted data, i.e. evaluation is always |
142 | 142 | disallowed with tainted regular expressions. See L<perlre/(?{ code })>. |
143 | 143 | |
144 | 144 | =end original |
145 | 145 | |
146 | 146 | C<use re 'eval'> が有効なとき、変数展開を含む正規表現でも |
147 | 147 | ゼロ幅表明 C<(?{ ... })> を持つことができます。 |
148 | 148 | これは通常はセキュリティ上のリスクとなる可能性があるので許されていません。 |
149 | 149 | このプラグマは正規表現が汚染されたデータからきたものである場合には |
150 | 150 | 無視されることに注意してください。 |
151 | 151 | つまり、汚染された正規表現を評価することは常に許されません。 |
152 | 152 | L<perlre/(?{ code })> を参照してください。 |
153 | 153 | |
154 | 154 | =begin original |
155 | 155 | |
156 | 156 | For the purpose of this pragma, interpolation of precompiled regular |
157 | 157 | expressions (i.e., the result of C<qr//>) is I<not> considered variable |
158 | 158 | interpolation. Thus: |
159 | 159 | |
160 | 160 | =end original |
161 | 161 | |
162 | 162 | このプラグマの目的のため、プリコンパイルされた正規表現 |
163 | 163 | (つまり、C<qr//> の結果)の展開(interpolation)は変数展開とは |
164 | 164 | I<みなされません>。 |
165 | 165 | したがって: |
166 | 166 | |
167 | 167 | /foo${pat}bar/ |
168 | 168 | |
169 | 169 | =begin original |
170 | 170 | |
171 | 171 | I<is> allowed if $pat is a precompiled regular expression, even |
172 | 172 | if $pat contains C<(?{ ... })> assertions. |
173 | 173 | |
174 | 174 | =end original |
175 | 175 | |
176 | 176 | は、$pat がプリコンパイルされた正規表現であれば、たとえ $pat が |
177 | 177 | C<(?{ ... })> 表明を含んでいたとしても I<許されます>。 |
178 | 178 | |
179 | 179 | =head2 'debug' mode |
180 | 180 | |
181 | 181 | ('debug' モード) |
182 | 182 | |
183 | 183 | =begin original |
184 | 184 | |
185 | 185 | When C<use re 'debug'> is in effect, perl emits debugging messages when |
186 | 186 | compiling and using regular expressions. The output is the same as that |
187 | 187 | obtained by running a C<-DDEBUGGING>-enabled perl interpreter with the |
188 | 188 | B<-Dr> switch. It may be quite voluminous depending on the complexity |
189 | 189 | of the match. Using C<debugcolor> instead of C<debug> enables a |
190 | 190 | form of output that can be used to get a colorful display on terminals |
191 | 191 | that understand termcap color sequences. Set C<$ENV{PERL_RE_TC}> to a |
192 | 192 | comma-separated list of C<termcap> properties to use for highlighting |
193 | 193 | strings on/off, pre-point part on/off. |
194 | 194 | See L<perldebug/"Debugging regular expressions"> for additional info. |
195 | 195 | |
196 | 196 | =end original |
197 | 197 | |
198 | 198 | C<use re 'debug'> が有効なとき、perl は正規表現をコンパイルするときと |
199 | 199 | 使うときにデバッグ用メッセージを出力します。 |
200 | 200 | その出力は C<-DDEBUGGING> が有効になっている perl インタプリタに |
201 | 201 | B<-Dr> スイッチを与えたときと同じです。 |
202 | 202 | これはマッチの複雑さに応じて非常に多弁になる可能性があります。 |
203 | 203 | C<debug> の代わりに C<debugcolor> を使うと、termcap カラーシーケンスを |
204 | 204 | 使ったカラフルな出力を端末に行います。 |
205 | 205 | C<termcap> プロパティのカンマ区切りのリストを C<$ENV{PERL_RE_TC}> に |
206 | 206 | セットすることで、文字列のオン/オフや pre-point 部分のオン/オフを |
207 | 207 | ハイライトできます。 |
208 | 208 | 更なる情報については |
209 | 209 | L<perldebug/"Debugging regular expressions"> を参照してください。 |
210 | 210 | |
211 | 211 | =begin original |
212 | 212 | |
213 | 213 | As of 5.9.5 the directive C<use re 'debug'> and its equivalents are |
214 | 214 | lexically scoped, as the other directives are. However they have both |
215 | 215 | compile-time and run-time effects. |
216 | 216 | |
217 | 217 | =end original |
218 | 218 | |
219 | 219 | 5.9.5 現在、 |
220 | 220 | C<use re 'debug'> 指示子およびそれと等価な設定は、他の指示子と同様 |
221 | 221 | レキシカルスコープです。 |
222 | 222 | しかしこれらはコンパイル時と実行時の両方に影響を及ぼします。 |
223 | 223 | |
224 | 224 | =begin original |
225 | 225 | |
226 | 226 | See L<perlmodlib/Pragmatic Modules>. |
227 | 227 | |
228 | 228 | =end original |
229 | 229 | |
230 | 230 | L<perlmodlib/Pragmatic Modules> を参照してください。 |
231 | 231 | |
232 | 232 | =head2 'Debug' mode |
233 | 233 | |
234 | 234 | ('Debug' モード) |
235 | 235 | |
236 | 236 | =begin original |
237 | 237 | |
238 | 238 | Similarly C<use re 'Debug'> produces debugging output, the difference |
239 | 239 | being that it allows the fine tuning of what debugging output will be |
240 | 240 | emitted. Options are divided into three groups, those related to |
241 | 241 | compilation, those related to execution and those related to special |
242 | 242 | purposes. The options are as follows: |
243 | 243 | |
244 | 244 | =end original |
245 | 245 | |
246 | 246 | C<use re 'Debug'> と同様にデバッグ出力を生成しますが、 |
247 | 247 | どのデバッグ情報が出力されるかを細かく制御できることが違います。 |
248 | 248 | 操作は、コンパイル関係、実行関係、特殊用途関係の 3 つのグループに |
249 | 249 | 分割されます。 |
250 | 250 | オプションは以下の通りです: |
251 | 251 | |
252 | 252 | =over 4 |
253 | 253 | |
254 | 254 | =item Compile related options |
255 | 255 | |
256 | 256 | (コンパイル関係オプション) |
257 | 257 | |
258 | 258 | =over 4 |
259 | 259 | |
260 | 260 | =item COMPILE |
261 | 261 | |
262 | 262 | =begin original |
263 | 263 | |
264 | 264 | Turns on all compile related debug options. |
265 | 265 | |
266 | 266 | =end original |
267 | 267 | |
268 | 268 | コンパイル関係のオプションを全て有効にします。 |
269 | 269 | |
270 | 270 | =item PARSE |
271 | 271 | |
272 | 272 | =begin original |
273 | 273 | |
274 | 274 | Turns on debug output related to the process of parsing the pattern. |
275 | 275 | |
276 | 276 | =end original |
277 | 277 | |
278 | 278 | パターンのパース処理に関係するデバッグ出力を有効にします。 |
279 | 279 | |
280 | 280 | =item OPTIMISE |
281 | 281 | |
282 | 282 | =begin original |
283 | 283 | |
284 | 284 | Enables output related to the optimisation phase of compilation. |
285 | 285 | |
286 | 286 | =end original |
287 | 287 | |
288 | 288 | コンパイルの最適化フェーズに関係するデバッグ出力を有効にします。 |
289 | 289 | |
290 | 290 | =item TRIEC |
291 | 291 | |
292 | 292 | =begin original |
293 | 293 | |
294 | 294 | Detailed info about trie compilation. |
295 | 295 | |
296 | 296 | =end original |
297 | 297 | |
298 | 298 | トライ木のコンパイルに関する詳細情報。 |
299 | 299 | |
300 | 300 | =item DUMP |
301 | 301 | |
302 | 302 | =begin original |
303 | 303 | |
304 | 304 | Dump the final program out after it is compiled and optimised. |
305 | 305 | |
306 | 306 | =end original |
307 | 307 | |
308 | 308 | コンパイルと最適化の後の最終的なプログラムの出力をダンプします。 |
309 | 309 | |
310 | 310 | =back |
311 | 311 | |
312 | 312 | =item Execute related options |
313 | 313 | |
314 | 314 | (実行関係オプション) |
315 | 315 | |
316 | 316 | =over 4 |
317 | 317 | |
318 | 318 | =item EXECUTE |
319 | 319 | |
320 | 320 | =begin original |
321 | 321 | |
322 | 322 | Turns on all execute related debug options. |
323 | 323 | |
324 | 324 | =end original |
325 | 325 | |
326 | 326 | 実行関係のデバッグオプションを全て有効にします。 |
327 | 327 | |
328 | 328 | =item MATCH |
329 | 329 | |
330 | 330 | =begin original |
331 | 331 | |
332 | 332 | Turns on debugging of the main matching loop. |
333 | 333 | |
334 | 334 | =end original |
335 | 335 | |
336 | 336 | メインマッチングループのデバッグを有効にします。 |
337 | 337 | |
338 | 338 | =item TRIEE |
339 | 339 | |
340 | 340 | =begin original |
341 | 341 | |
342 | 342 | Extra debugging of how tries execute. |
343 | 343 | |
344 | 344 | =end original |
345 | 345 | |
346 | 346 | トライ木をどのように実行するかに関する追加のデバッグ。 |
347 | 347 | |
348 | 348 | =item INTUIT |
349 | 349 | |
350 | 350 | =begin original |
351 | 351 | |
352 | 352 | Enable debugging of start point optimisations. |
353 | 353 | |
354 | 354 | =end original |
355 | 355 | |
356 | 356 | 開始点最適化のデバッグを有効にします。 |
357 | 357 | |
358 | 358 | =back |
359 | 359 | |
360 | 360 | =item Extra debugging options |
361 | 361 | |
362 | 362 | (追加デバッグオプション) |
363 | 363 | |
364 | 364 | =over 4 |
365 | 365 | |
366 | 366 | =item EXTRA |
367 | 367 | |
368 | 368 | =begin original |
369 | 369 | |
370 | 370 | Turns on all "extra" debugging options. |
371 | 371 | |
372 | 372 | =end original |
373 | 373 | |
374 | 374 | 「追加の」デバッグオプションを全て有効にします。 |
375 | 375 | |
376 | 376 | =item BUFFERS |
377 | 377 | |
378 | 378 | =begin original |
379 | 379 | |
380 | 380 | Enable debugging the capture buffer storage during match. Warning, |
381 | 381 | this can potentially produce extremely large output. |
382 | 382 | |
383 | 383 | =end original |
384 | 384 | |
385 | 385 | マッチング中の捕捉バッファのデバッグを有効にします。 |
386 | 386 | これは極めて大きい出力を生成する可能性があることを警告しておきます。 |
387 | 387 | |
388 | 388 | =item TRIEM |
389 | 389 | |
390 | 390 | =begin original |
391 | 391 | |
392 | 392 | Enable enhanced TRIE debugging. Enhances both TRIEE |
393 | 393 | and TRIEC. |
394 | 394 | |
395 | 395 | =end original |
396 | 396 | |
397 | 397 | 拡張された TRIE デバッグを有効にします。 |
398 | 398 | TRIEE と TRIEC の両方を拡張します。 |
399 | 399 | |
400 | 400 | =item STATE |
401 | 401 | |
402 | 402 | =begin original |
403 | 403 | |
404 | 404 | Enable debugging of states in the engine. |
405 | 405 | |
406 | 406 | =end original |
407 | 407 | |
408 | 408 | エンジンの状態のデバッグを有効にします。 |
409 | 409 | |
410 | 410 | =item STACK |
411 | 411 | |
412 | 412 | =begin original |
413 | 413 | |
414 | 414 | Enable debugging of the recursion stack in the engine. Enabling |
415 | 415 | or disabling this option automatically does the same for debugging |
416 | 416 | states as well. This output from this can be quite large. |
417 | 417 | |
418 | 418 | =end original |
419 | 419 | |
420 | 420 | エンジンの再帰スタックのデバッグを有効にします。 |
421 | 421 | このオプションを有効または無効にすると、デバッグ状態も同様に |
422 | 422 | 同じ状態になります。 |
423 | 423 | この出力はかなり大きくなることがあります。 |
424 | 424 | |
425 | 425 | =item OPTIMISEM |
426 | 426 | |
427 | 427 | =begin original |
428 | 428 | |
429 | 429 | Enable enhanced optimisation debugging and start point optimisations. |
430 | 430 | Probably not useful except when debugging the regex engine itself. |
431 | 431 | |
432 | 432 | =end original |
433 | 433 | |
434 | 434 | 拡張最適化デバッグと開始位置最適化を有効にします。 |
435 | 435 | 正規表現自身をデバッグするのでなければ、おそらく有用ではありません。 |
436 | 436 | |
437 | 437 | =item OFFSETS |
438 | 438 | |
439 | 439 | =begin original |
440 | 440 | |
441 | 441 | Dump offset information. This can be used to see how regops correlate |
442 | 442 | to the pattern. Output format is |
443 | 443 | |
444 | 444 | =end original |
445 | 445 | |
446 | 446 | オフセット情報をダンプします。 |
447 | 447 | これは、どのように regops がパターンと関連するかを見るために使えます。 |
448 | 448 | 出力フォーマットは |
449 | 449 | |
450 | 450 | NODENUM:POSITION[LENGTH] |
451 | 451 | |
452 | 452 | =begin original |
453 | 453 | |
454 | 454 | Where 1 is the position of the first char in the string. Note that position |
455 | 455 | can be 0, or larger than the actual length of the pattern, likewise length |
456 | 456 | can be zero. |
457 | 457 | |
458 | 458 | =end original |
459 | 459 | |
460 | 460 | 文字列の最初の文字の位置は 1 です。 |
461 | 461 | 位置が 0 であったり、パターンの実際の長さより大きかったり、 |
462 | 462 | 長さが 0 であったりするかもしれないことに注意してください。 |
463 | 463 | |
464 | 464 | =item OFFSETSDBG |
465 | 465 | |
466 | 466 | =begin original |
467 | 467 | |
468 | 468 | Enable debugging of offsets information. This emits copious |
469 | 469 | amounts of trace information and doesn't mesh well with other |
470 | 470 | debug options. |
471 | 471 | |
472 | 472 | =end original |
473 | 473 | |
474 | 474 | オフセット情報のデバッグを有効にします。 |
475 | 475 | これは大量のトレース情報を出力し、他のデバッグオプションとはうまく |
476 | 476 | かみ合いません。 |
477 | 477 | |
478 | 478 | =begin original |
479 | 479 | |
480 | 480 | Almost definitely only useful to people hacking |
481 | 481 | on the offsets part of the debug engine. |
482 | 482 | |
483 | 483 | =end original |
484 | 484 | |
485 | 485 | ほぼ確実に、デバッグエンジンのオフセット部分をハックする人々によってのみ |
486 | 486 | 有用です。 |
487 | 487 | |
488 | 488 | =back |
489 | 489 | |
490 | 490 | =item Other useful flags |
491 | 491 | |
492 | 492 | (その他の便利なフラグ) |
493 | 493 | |
494 | 494 | =begin original |
495 | 495 | |
496 | 496 | These are useful shortcuts to save on the typing. |
497 | 497 | |
498 | 498 | =end original |
499 | 499 | |
500 | 500 | タイプ数を節約するための便利な短縮記法があります。 |
501 | 501 | |
502 | 502 | =over 4 |
503 | 503 | |
504 | 504 | =item ALL |
505 | 505 | |
506 | 506 | =begin original |
507 | 507 | |
508 | 508 | Enable all options at once except OFFSETS, OFFSETSDBG and BUFFERS |
509 | 509 | |
510 | 510 | =end original |
511 | 511 | |
512 | 512 | OFFSETS, OFFSETSDBG, BUFFERS 以外の全てのオプションを有効にします。 |
513 | 513 | |
514 | 514 | =item All |
515 | 515 | |
516 | 516 | =begin original |
517 | 517 | |
518 | 518 | Enable DUMP and all execute options. Equivalent to: |
519 | 519 | |
520 | 520 | =end original |
521 | 521 | |
522 | 522 | DUMP と、全ての実行関係のオプションを有効にします。 |
523 | 523 | 以下と等価です: |
524 | 524 | |
525 | 525 | use re 'debug'; |
526 | 526 | |
527 | 527 | =item MORE |
528 | 528 | |
529 | 529 | =item More |
530 | 530 | |
531 | 531 | =begin original |
532 | 532 | |
533 | 533 | Enable TRIEM and all execute compile and execute options. |
534 | 534 | |
535 | 535 | =end original |
536 | 536 | |
537 | 537 | TRIEM と、全てのコンパイル関係および実行関係のオプションを有効にします。 |
538 | 538 | |
539 | 539 | =back |
540 | 540 | |
541 | 541 | =back |
542 | 542 | |
543 | 543 | =begin original |
544 | 544 | |
545 | 545 | As of 5.9.5 the directive C<use re 'debug'> and its equivalents are |
546 | 546 | lexically scoped, as the other directives are. However they have both |
547 | 547 | compile-time and run-time effects. |
548 | 548 | |
549 | 549 | =end original |
550 | 550 | |
551 | 551 | 5.9.5 以降、C<use re 'debug'> 指示子およびその等価物は、その他の指示子と同様 |
552 | 552 | レキシカルスコープを持ちます。 |
553 | 553 | しかし、これらはコンパイル時と実行時の両方で効果があります。 |
554 | 554 | |
555 | 555 | =head2 Exportable Functions |
556 | 556 | |
557 | 557 | (エクスポート可能な関数) |
558 | 558 | |
559 | 559 | =begin original |
560 | 560 | |
561 | 561 | As of perl 5.9.5 're' debug contains a number of utility functions that |
562 | 562 | may be optionally exported into the caller's namespace. They are listed |
563 | 563 | below. |
564 | 564 | |
565 | 565 | =end original |
566 | 566 | |
567 | 567 | perl 5.9.5 以降、're' debug には、呼び出し元の名前空間にエクスポートできる、 |
568 | 568 | いくつかの便利関数を含んでいます。 |
569 | 569 | 以下に一覧を示します。 |
570 | 570 | |
571 | 571 | =over 4 |
572 | 572 | |
573 | 573 | =item is_regexp($ref) |
574 | 574 | |
575 | 575 | =begin original |
576 | 576 | |
577 | 577 | Returns true if the argument is a compiled regular expression as returned |
578 | 578 | by C<qr//>, false if it is not. |
579 | 579 | |
580 | 580 | =end original |
581 | 581 | |
582 | 582 | 引数が、C<qr//> から返された、コンパイル済み正規表現の場合は真を、 |
583 | 583 | さもなければ偽を返します。 |
584 | 584 | |
585 | 585 | =begin original |
586 | 586 | |
587 | 587 | This function will not be confused by overloading or blessing. In |
588 | 588 | internals terms, this extracts the regexp pointer out of the |
589 | 589 | PERL_MAGIC_qr structure so it it cannot be fooled. |
590 | 590 | |
591 | 591 | =end original |
592 | 592 | |
593 | 593 | この関数はオーバーロードや bless によって混乱しません。 |
594 | 594 | 内部用語で言うと、PERL_MAGIC_qr 構造体から正規表現ポインタを |
595 | 595 | 取り出しているので、だまされることはありません。 |
596 | 596 | |
597 | 597 | =item regexp_pattern($ref) |
598 | 598 | |
599 | 599 | =begin original |
600 | 600 | |
601 | 601 | If the argument is a compiled regular expression as returned by C<qr//>, |
602 | 602 | then this function returns the pattern. |
603 | 603 | |
604 | 604 | =end original |
605 | 605 | |
606 | 606 | 引数が、C<qr//> から返された、コンパイル済み正規表現の場合、 |
607 | 607 | この関数はパターンを返します。 |
608 | 608 | |
609 | 609 | =begin original |
610 | 610 | |
611 | 611 | In list context it returns a two element list, the first element |
612 | 612 | containing the pattern and the second containing the modifiers used when |
613 | 613 | the pattern was compiled. |
614 | 614 | |
615 | 615 | =end original |
616 | 616 | |
617 | 617 | リストコンテキストでは 2 要素のリストを返し、1 番目の要素はパターン、 |
618 | 618 | 2 番目はパターンがコンパイルされたときに使われた修飾子です。 |
619 | 619 | |
620 | 620 | my ($pat, $mods) = regexp_pattern($ref); |
621 | 621 | |
622 | 622 | =begin original |
623 | 623 | |
624 | 624 | In scalar context it returns the same as perl would when strigifying a raw |
625 | 625 | C<qr//> with the same pattern inside. If the argument is not a compiled |
626 | 626 | reference then this routine returns false but defined in scalar context, |
627 | 627 | and the empty list in list context. Thus the following |
628 | 628 | |
629 | 629 | =end original |
630 | 630 | |
631 | 631 | スカラコンテキストでは、生の C<qr//> の中に書くことで perl が |
632 | 632 | 文字列化したときに同じ内容になるものを返します。 |
633 | 633 | 引数がコンパイルされたリファレンスではない場合、スカラコンテキストでは |
634 | 634 | 「偽だが定義済み」を返し、リストコンテキストでは空リストを返します。 |
635 | 635 | 従って、以下の文 |
636 | 636 | |
637 | 637 | if (regexp_pattern($ref) eq '(?i-xsm:foo)') |
638 | 638 | |
639 | 639 | =begin original |
640 | 640 | |
641 | 641 | will be warning free regardless of what $ref actually is. |
642 | 642 | |
643 | 643 | =end original |
644 | 644 | |
645 | 645 | は、実際の $ref が何であっても警告は出ません。 |
646 | 646 | |
647 | 647 | =begin original |
648 | 648 | |
649 | 649 | Like C<is_regexp> this function will not be confused by overloading |
650 | 650 | or blessing of the object. |
651 | 651 | |
652 | 652 | =end original |
653 | 653 | |
654 | 654 | C<is_regexp> と同様、この関数はオブジェクトのオーバーロードや bless によって |
655 | 655 | 混乱しません。 |
656 | 656 | |
657 | 657 | =item regmust($ref) |
658 | 658 | |
659 | 659 | =begin original |
660 | 660 | |
661 | 661 | If the argument is a compiled regular expression as returned by C<qr//>, |
662 | 662 | then this function returns what the optimiser consiers to be the longest |
663 | 663 | anchored fixed string and longest floating fixed string in the pattern. |
664 | 664 | |
665 | 665 | =end original |
666 | 666 | |
667 | 667 | 引数が C<qr//> で返されたコンパイル済み正規表現の場合、この関数は、 |
668 | 668 | パターンの中でオプティマイザが最長の不動不変文字列および最長の |
669 | 669 | 浮遊不変文字列と考えたものを返します。 |
670 | 670 | |
671 | 671 | =begin original |
672 | 672 | |
673 | 673 | A I<fixed string> is defined as being a substring that must appear for the |
674 | 674 | pattern to match. An I<anchored fixed string> is a fixed string that must |
675 | 675 | appear at a particular offset from the beginning of the match. A I<floating |
676 | 676 | fixed string> is defined as a fixed string that can appear at any point in |
677 | 677 | a range of positions relative to the start of the match. For example, |
678 | 678 | |
679 | 679 | =end original |
680 | 680 | |
681 | 681 | I<不変文字列> (fixed string) とは、マッチングするパターンとして |
682 | 682 | 現れなければならない部分文字列として定義されます。 |
683 | 683 | I<不動不変文字列> (anchored fixed string) とは、マッチングの開始からの |
684 | 684 | 特定の位置に現れなければならない不変文字列です。 |
685 | 685 | I<浮遊不変文字列> (floating fixed string) とは、マッチングの開始からの |
686 | 686 | 相対位置の範囲でどの位置に現れてもよい不変文字列として定義されます。 |
687 | 687 | 例えば、 |
688 | 688 | |
689 | 689 | my $qr = qr/here .* there/x; |
690 | 690 | my ($anchored, $floating) = regmust($qr); |
691 | 691 | print "anchored:'$anchored'\nfloating:'$floating'\n"; |
692 | 692 | |
693 | 693 | =begin original |
694 | 694 | |
695 | 695 | results in |
696 | 696 | |
697 | 697 | =end original |
698 | 698 | |
699 | 699 | これの結果は |
700 | 700 | |
701 | 701 | anchored:'here' |
702 | 702 | floating:'there' |
703 | 703 | |
704 | 704 | =begin original |
705 | 705 | |
706 | 706 | Because the C<here> is before the C<.*> in the pattern, its position |
707 | 707 | can be determined exactly. That's not true, however, for the C<there>; |
708 | 708 | it could appear at any point after where the anchored string appeared. |
709 | 709 | Perl uses both for its optimisations, prefering the longer, or, if they are |
710 | 710 | equal, the floating. |
711 | 711 | |
712 | 712 | =end original |
713 | 713 | |
714 | 714 | パターンの中で C<here> は C<.*> の前にあるので、この位置は正確に |
715 | 715 | 決定されます。 |
716 | 716 | しかし、このことは C<there> には当てはまりません; |
717 | 717 | これは不動不変文字列の後ならどの地点にでも現れる可能性があります。 |
718 | 718 | Perl は最適化のためにこれらの両方を、長い方(同じ場合は浮遊)を優先して |
719 | 719 | 使います。 |
720 | 720 | |
721 | 721 | =begin original |
722 | 722 | |
723 | 723 | B<NOTE:> This may not necessarily be the definitive longest anchored and |
724 | 724 | floating string. This will be what the optimiser of the Perl that you |
725 | 725 | are using thinks is the longest. If you believe that the result is wrong |
726 | 726 | please report it via the L<perlbug> utility. |
727 | 727 | |
728 | 728 | =end original |
729 | 729 | |
730 | 730 | B<注意:> これは最終的な最長の不動及び浮遊文字列とは限りません。 |
731 | 731 | これは Perl のオプティマイザが最長と考えたものです。 |
732 | 732 | もし結果が間違っていると信じるなら、L<perlbug> ユーティリティ経由で |
733 | 733 | 報告を送ってください。 |
734 | 734 | |
735 | 735 | =item regname($name,$all) |
736 | 736 | |
737 | 737 | =begin original |
738 | 738 | |
739 | 739 | Returns the contents of a named buffer of the last successful match. If |
740 | 740 | $all is true, then returns an array ref containing one entry per buffer, |
741 | 741 | otherwise returns the first defined buffer. |
742 | 742 | |
743 | 743 | =end original |
744 | 744 | |
745 | 745 | 最後に成功したマッチングの名前付きバッファの内容を返します。 |
746 | 746 | $all が真なら、バッファごとに一つの要素となる配列リファレンスを返します; |
747 | 747 | さもなければ最初に定義されたバッファを返します。 |
748 | 748 | |
749 | 749 | =item regnames($all) |
750 | 750 | |
751 | 751 | =begin original |
752 | 752 | |
753 | 753 | Returns a list of all of the named buffers defined in the last successful |
754 | 754 | match. If $all is true, then it returns all names defined, if not it returns |
755 | 755 | only names which were involved in the match. |
756 | 756 | |
757 | 757 | =end original |
758 | 758 | |
759 | 759 | 最後に成功したマッチングで定義された全ての名前付きバッファのリストを |
760 | 760 | 返します。 |
761 | 761 | $all が真なら、定義された全ての名前を返します; |
762 | 762 | さもなければマッチングに関わった名前のみを返します。 |
763 | 763 | |
764 | 764 | =item regnames_count() |
765 | 765 | |
766 | 766 | =begin original |
767 | 767 | |
768 | 768 | Returns the number of distinct names defined in the pattern used |
769 | 769 | for the last successful match. |
770 | 770 | |
771 | 771 | =end original |
772 | 772 | |
773 | 773 | 最後に成功したマッチングで使われたパターンで定義された、異なる名前の数を |
774 | 774 | 返します。 |
775 | 775 | |
776 | 776 | =begin original |
777 | 777 | |
778 | 778 | B<Note:> this result is always the actual number of distinct |
779 | 779 | named buffers defined, it may not actually match that which is |
780 | 780 | returned by C<regnames()> and related routines when those routines |
781 | 781 | have not been called with the $all parameter set. |
782 | 782 | |
783 | 783 | =end original |
784 | 784 | |
785 | 785 | B<注意:> この結果は常に、定義された異なる名前付きバッファの実際の数となり、 |
786 | 786 | C<regnames()> や関連するルーチンが $all 引数をセットせずに呼び出された |
787 | 787 | 場合に返したものと一致しないことがあります。 |
788 | 788 | |
789 | 789 | =back |
790 | 790 | |
791 | 791 | =head1 SEE ALSO |
792 | 792 | |
793 | 793 | L<perlmodlib/Pragmatic Modules>. |
794 | 794 | |
795 | 795 | =begin meta |
796 | 796 | |
797 | 797 | Translate: KIMURA Koichi (0.04) |
798 | Update: Kentaro Shirakata <argrath@ub32.org> (0.08 | |
798 | Update: Kentaro Shirakata <argrath@ub32.org> (0.08) | |
799 | 799 | |
800 | 800 | =end meta |
801 | 801 | |
802 | 802 | =cut |