1 |
|
2 |
=encoding euc-jp |
3 |
|
4 |
=head1 NAME |
5 |
|
6 |
=begin original |
7 |
|
8 |
perlreref - Perl Regular Expressions Reference |
9 |
|
10 |
=end original |
11 |
|
12 |
perlreref - Perl の正規表現のリファレンス |
13 |
|
14 |
=head1 DESCRIPTION |
15 |
|
16 |
=begin original |
17 |
|
18 |
This is a quick reference to Perl's regular expressions. |
19 |
For full information see L<perlre> and L<perlop>, as well |
20 |
as the L</"SEE ALSO"> section in this document. |
21 |
|
22 |
=end original |
23 |
|
24 |
本ドキュメントは、Perl の正規表現のクイックリファレンスです。 |
25 |
完全な情報は、L<perlre> と L<perlop>、また、本ドキュメントの |
26 |
L</"SEE ALSO"> セクションを参照してください。 |
27 |
|
28 |
=head2 OPERATORS |
29 |
|
30 |
(演算子) |
31 |
|
32 |
=begin original |
33 |
|
34 |
C<=~> determines to which variable the regex is applied. |
35 |
In its absence, $_ is used. |
36 |
|
37 |
=end original |
38 |
|
39 |
C<=~> は正規表現が適用される変数を決定します。 |
40 |
省略された場合には、$_ が使われます。 |
41 |
|
42 |
$var =~ /foo/; |
43 |
|
44 |
=begin original |
45 |
|
46 |
C<!~> determines to which variable the regex is applied, |
47 |
and negates the result of the match; it returns |
48 |
false if the match succeeds, and true if it fails. |
49 |
|
50 |
=end original |
51 |
|
52 |
C<!~> は正規表現が適用される変数を決定し、マッチの結果を反転します; |
53 |
マッチが成功すれば偽を返し、失敗すれば真を返します。 |
54 |
|
55 |
$var !~ /foo/; |
56 |
|
57 |
=begin original |
58 |
|
59 |
C<m/pattern/msixpogcdual> searches a string for a pattern match, |
60 |
applying the given options. |
61 |
|
62 |
=end original |
63 |
|
64 |
C<m/pattern/msixpogcdual> パターンマッチのために文字列を検索し、 |
65 |
与えられたオプションを適用します。 |
66 |
|
67 |
=begin original |
68 |
|
69 |
m Multiline mode - ^ and $ match internal lines |
70 |
s match as a Single line - . matches \n |
71 |
i case-Insensitive |
72 |
x eXtended legibility - free whitespace and comments |
73 |
p Preserve a copy of the matched string - |
74 |
${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be defined. |
75 |
o compile pattern Once |
76 |
g Global - all occurrences |
77 |
c don't reset pos on failed matches when using /g |
78 |
a restrict \d, \s, \w and [:posix:] to match ASCII only |
79 |
aa (two a's) also /i matches exclude ASCII/non-ASCII |
80 |
l match according to current locale |
81 |
u match according to Unicode rules |
82 |
d match according to native rules unless something indicates |
83 |
Unicode |
84 |
|
85 |
=end original |
86 |
|
87 |
m 複数行モード - ^ と $ が内部的な行にマッチします |
88 |
s 単行としてマッチ - . が \n にマッチします |
89 |
i 大小文字の違いを無視します |
90 |
x 読みやすさの拡張 - 空白やコメントを自由に置けます |
91 |
p マッチした文字列のコピーを保存する - |
92 |
${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} が定義されます。 |
93 |
o パターンを一度だけコンパイルします |
94 |
g グローバル - マッチするものすべて |
95 |
c /g を使っているときにマッチに失敗しても pos をリセットしません |
96 |
a \d, \s, \w, [:posix:] で ASCII のみにマッチングするように制限 |
97 |
aa (二つの a) また /i のマッチングは ASCII/非-ASCII を除外 |
98 |
l 現在のロケールに従ってマッチング |
99 |
u Unicode のルールに従ってマッチング |
100 |
d Unicode を示すものがない限りネイティブなルールに従ってマッチング |
101 |
|
102 |
=begin original |
103 |
|
104 |
If 'pattern' is an empty string, the last I<successfully> matched |
105 |
regex is used. Delimiters other than '/' may be used for both this |
106 |
operator and the following ones. The leading C<m> can be omitted |
107 |
if the delimiter is '/'. |
108 |
|
109 |
=end original |
110 |
|
111 |
'pattern' が空文字列なら、最後にマッチングに I<成功した> |
112 |
正規表現が使われます。 |
113 |
この演算子とそれに続くものの両方で、'/' 以外のデリミタも使えます。 |
114 |
デリミタが '/' の場合は C<m> は省略できます。 |
115 |
|
116 |
=begin original |
117 |
|
118 |
C<qr/pattern/msixpodual> lets you store a regex in a variable, |
119 |
or pass one around. Modifiers as for C<m//>, and are stored |
120 |
within the regex. |
121 |
|
122 |
=end original |
123 |
|
124 |
C<qr/pattern/msixpodual> は、正規表現を変数に入れるか、順に回せるように |
125 |
します。 |
126 |
C<m//> と同じ修飾子が使えて、正規表現に保管されます。 |
127 |
|
128 |
=begin original |
129 |
|
130 |
C<s/pattern/replacement/msixpogcedual> substitutes matches of |
131 |
'pattern' with 'replacement'. Modifiers as for C<m//>, |
132 |
with two additions: |
133 |
|
134 |
=end original |
135 |
|
136 |
C<s/pattern/replacement/msixpogcedual> は、'pattern' でマッチしたものを |
137 |
'replacement' で置き換えます。 |
138 |
C<m//> と同じ修飾子が使えて、さらに二つ追加されます: |
139 |
|
140 |
=begin original |
141 |
|
142 |
e Evaluate 'replacement' as an expression |
143 |
r Return substitution and leave the original string untouched. |
144 |
|
145 |
=end original |
146 |
|
147 |
e 'replacement' を式として評価します |
148 |
r 置換した結果を返し、元の文字列は変更しません。 |
149 |
|
150 |
=begin original |
151 |
|
152 |
'e' may be specified multiple times. 'replacement' is interpreted |
153 |
as a double quoted string unless a single-quote (C<'>) is the delimiter. |
154 |
|
155 |
=end original |
156 |
|
157 |
'e' は複数回指定できます。 |
158 |
'replacement' は、デリミタとしてシングルクォート (C<'>) が使われた場合を |
159 |
除いて、ダブルクォートされた文字列として解釈されます。 |
160 |
|
161 |
=begin original |
162 |
|
163 |
C<?pattern?> is like C<m/pattern/> but matches only once. No alternate |
164 |
delimiters can be used. Must be reset with reset(). |
165 |
|
166 |
=end original |
167 |
|
168 |
C<?pattern?> は C<m/pattern/> に似ていますが、一度だけマッチします。 |
169 |
デリミタは変更できません。 |
170 |
reset() でリセットしなければなりません。 |
171 |
|
172 |
=head2 SYNTAX |
173 |
|
174 |
=begin original |
175 |
|
176 |
\ Escapes the character immediately following it |
177 |
. Matches any single character except a newline (unless /s is |
178 |
used) |
179 |
^ Matches at the beginning of the string (or line, if /m is used) |
180 |
$ Matches at the end of the string (or line, if /m is used) |
181 |
* Matches the preceding element 0 or more times |
182 |
+ Matches the preceding element 1 or more times |
183 |
? Matches the preceding element 0 or 1 times |
184 |
{...} Specifies a range of occurrences for the element preceding it |
185 |
[...] Matches any one of the characters contained within the brackets |
186 |
(...) Groups subexpressions for capturing to $1, $2... |
187 |
(?:...) Groups subexpressions without capturing (cluster) |
188 |
| Matches either the subexpression preceding or following it |
189 |
\g1 or \g{1}, \g2 ... Matches the text from the Nth group |
190 |
\1, \2, \3 ... Matches the text from the Nth group |
191 |
\g-1 or \g{-1}, \g-2 ... Matches the text from the Nth previous group |
192 |
\g{name} Named backreference |
193 |
\k<name> Named backreference |
194 |
\k'name' Named backreference |
195 |
(?P=name) Named backreference (python syntax) |
196 |
|
197 |
=end original |
198 |
|
199 |
\ 直後の文字をエスケープします |
200 |
. 改行を除く任意の一文字にマッチします (/s が使われていない場合) |
201 |
^ 文字列(/m が使われている場合は行)の先頭にマッチします |
202 |
$ 文字列(/m が使われている場合は行)の末尾にマッチします |
203 |
* 先行する要素のゼロ回以上の繰り返しにマッチします |
204 |
+ 先行する要素の一回以上の繰り返しにマッチします |
205 |
? 先行する要素のゼロ回または一回の出現にマッチします |
206 |
{...} 先行する要素の繰り返しの範囲を指定します |
207 |
[...] ブラケットの内側にある文字のいずれかにマッチします |
208 |
(...) $1, $2... のために部分正規表現をグループ化して捕捉します |
209 |
(?:...) 部分正規表現を捕捉することなくグループ化します (クラスター) |
210 |
| 左右いずれかにある部分正規表現にマッチします |
211 |
\g1 or \g{1}, \g2 ... N 番目のグループのテキストにマッチします |
212 |
\1, \2, \3 ... N 番目のグループのテキストにマッチします |
213 |
\g-1 or \g{-1}, \g-2 ... N 個前のグループのテキストにマッチします |
214 |
\g{name} 名前つき後方参照 |
215 |
\k<name> 名前つき後方参照 |
216 |
\k'name' 名前つき後方参照 |
217 |
(?P=name) 名前つき後方参照 (python の文法) |
218 |
|
219 |
=head2 ESCAPE SEQUENCES |
220 |
|
221 |
(エスケープシーケンス) |
222 |
|
223 |
=begin original |
224 |
|
225 |
These work as in normal strings. |
226 |
|
227 |
=end original |
228 |
|
229 |
これらは通常の文字列として働きます。 |
230 |
|
231 |
=begin original |
232 |
|
233 |
\a Alarm (beep) |
234 |
\e Escape |
235 |
\f Formfeed |
236 |
\n Newline |
237 |
\r Carriage return |
238 |
\t Tab |
239 |
\037 Char whose ordinal is the 3 octal digits, max \777 |
240 |
\o{2307} Char whose ordinal is the octal number, unrestricted |
241 |
\x7f Char whose ordinal is the 2 hex digits, max \xFF |
242 |
\x{263a} Char whose ordinal is the hex number, unrestricted |
243 |
\cx Control-x |
244 |
\N{name} A named Unicode character or character sequence |
245 |
\N{U+263D} A Unicode character by hex ordinal |
246 |
|
247 |
=end original |
248 |
|
249 |
\a アラーム (ビープ) |
250 |
\e エスケープ |
251 |
\f 改ページ |
252 |
\n 改行 |
253 |
\r キャリッジリターン |
254 |
\t タブ |
255 |
\037 番号が 3 桁の 8 進数である文字、最大 \777 |
256 |
\o{2307} 番号が 8 進数である文字、無制限 |
257 |
\x7f 番号が 2 桁の 16 進数である文字、最大 \xFF |
258 |
\x{263a} 番号が 16 進数である文字、無制限 |
259 |
\cx Control-x |
260 |
\N{name} 名前つき Unicode 文字または文字並び |
261 |
\N{U+263D} 16 進数による Unicode 文字 |
262 |
|
263 |
=begin original |
264 |
|
265 |
\l Lowercase next character |
266 |
\u Titlecase next character |
267 |
\L Lowercase until \E |
268 |
\U Uppercase until \E |
269 |
\F Foldcase until \E |
270 |
\Q Disable pattern metacharacters until \E |
271 |
\E End modification |
272 |
|
273 |
=end original |
274 |
|
275 |
\l 次の文字を小文字にします |
276 |
\u 次の文字をタイトル文字にします |
277 |
\L \E まで小文字にします |
278 |
\U \E まで大文字にします |
279 |
\F \E まで畳み込み文字にします |
280 |
\Q \E までパターンのメタ文字を無効にします |
281 |
\E 修正を終了します |
282 |
|
283 |
=begin original |
284 |
|
285 |
For Titlecase, see L</Titlecase>. |
286 |
|
287 |
=end original |
288 |
|
289 |
タイトル文字にについては L</Titlecase> を参照してください。 |
290 |
|
291 |
=begin original |
292 |
|
293 |
This one works differently from normal strings: |
294 |
|
295 |
=end original |
296 |
|
297 |
この 1 つは通常の文字列とは異なった働きをします: |
298 |
|
299 |
=begin original |
300 |
|
301 |
\b An assertion, not backspace, except in a character class |
302 |
|
303 |
=end original |
304 |
|
305 |
\b 文字クラスの中以外では、表明であってバックスペースではありません |
306 |
|
307 |
=head2 CHARACTER CLASSES |
308 |
|
309 |
(文字クラス) |
310 |
|
311 |
=begin original |
312 |
|
313 |
[amy] Match 'a', 'm' or 'y' |
314 |
[f-j] Dash specifies "range" |
315 |
[f-j-] Dash escaped or at start or end means 'dash' |
316 |
[^f-j] Caret indicates "match any character _except_ these" |
317 |
|
318 |
=end original |
319 |
|
320 |
[amy] 'a', 'm', 'y' のいずれかにマッチ |
321 |
[f-j] ダッシュは「範囲」を指定します |
322 |
[f-j-] エスケープされるか、最初か最後にあるダッシュは「ダッシュ」を意味します |
323 |
[^f-j] キャレットは「これら以外にマッチ」を示します |
324 |
|
325 |
=begin original |
326 |
|
327 |
The following sequences (except C<\N>) work within or without a character class. |
328 |
The first six are locale aware, all are Unicode aware. See L<perllocale> |
329 |
and L<perlunicode> for details. |
330 |
|
331 |
=end original |
332 |
|
333 |
(C<\N> 以外の)以下のシーケンスは文字クラス内でもそれ以外でも動作します。 |
334 |
最初の 6 つはロケールの影響を受け、全ては Unicode の影響を受けます。 |
335 |
詳細については L<perllocale> と L<perlunicode> を参照してください。 |
336 |
|
337 |
=begin original |
338 |
|
339 |
\d A digit |
340 |
\D A nondigit |
341 |
\w A word character |
342 |
\W A non-word character |
343 |
\s A whitespace character |
344 |
\S A non-whitespace character |
345 |
\h An horizontal whitespace |
346 |
\H A non horizontal whitespace |
347 |
\N A non newline (when not followed by '{NAME}';; |
348 |
not valid in a character class; equivalent to [^\n]; it's |
349 |
like '.' without /s modifier) |
350 |
\v A vertical whitespace |
351 |
\V A non vertical whitespace |
352 |
\R A generic newline (?>\v|\x0D\x0A) |
353 |
|
354 |
=end original |
355 |
|
356 |
\d 数値 |
357 |
\D 非数値 |
358 |
\w 単語文字 |
359 |
\W 非単語文字 |
360 |
\s 空白文字 |
361 |
\S 非空白文字 |
362 |
\h 水平空白文字 |
363 |
\H 非水平空白文字 |
364 |
\N 非改行 ('{NAME}' に引き続いていない場合;; 文字クラスでは |
365 |
不正; [^\n] と等価; /s なしの場合の '.' と同様) |
366 |
\v 垂直空白文字 |
367 |
\V 非垂直空白文字 |
368 |
\R 一般的な改行 (?>\v|\x0D\x0A) |
369 |
|
370 |
=begin original |
371 |
|
372 |
\C Match a byte (with Unicode, '.' matches a character) |
373 |
(Deprecated.) |
374 |
\pP Match P-named (Unicode) property |
375 |
\p{...} Match Unicode property with name longer than 1 character |
376 |
\PP Match non-P |
377 |
\P{...} Match lack of Unicode property with name longer than 1 char |
378 |
\X Match Unicode extended grapheme cluster |
379 |
|
380 |
=end original |
381 |
|
382 |
\C 1 バイトにマッチする (Unicode では、'.' は文字にマッチする) |
383 |
(廃止予定。) |
384 |
\pP P の名前の (Unicode) プロパティ |
385 |
\p{...} 1 文字より長い名前の Unicode プロパティにマッチする |
386 |
\PP 非 P にマッチする |
387 |
\P{...} 1 文字より長い名前の Unicode プロパティがないものにマッチする |
388 |
\X Unicode の拡張書記素クラスタにマッチする |
389 |
|
390 |
=begin original |
391 |
|
392 |
POSIX character classes and their Unicode and Perl equivalents: |
393 |
|
394 |
=end original |
395 |
|
396 |
POSIX 文字クラスと、それに対する Unicode と Perl の相当物は: |
397 |
|
398 |
ASCII- Full- |
399 |
POSIX range range backslash |
400 |
[[:...:]] \p{...} \p{...} sequence Description |
401 |
|
402 |
=begin original |
403 |
|
404 |
----------------------------------------------------------------------- |
405 |
alnum PosixAlnum XPosixAlnum Alpha plus Digit |
406 |
alpha PosixAlpha XPosixAlpha Alphabetic characters |
407 |
ascii ASCII Any ASCII character |
408 |
blank PosixBlank XPosixBlank \h Horizontal whitespace; |
409 |
full-range also |
410 |
written as |
411 |
\p{HorizSpace} (GNU |
412 |
extension) |
413 |
cntrl PosixCntrl XPosixCntrl Control characters |
414 |
digit PosixDigit XPosixDigit \d Decimal digits |
415 |
graph PosixGraph XPosixGraph Alnum plus Punct |
416 |
lower PosixLower XPosixLower Lowercase characters |
417 |
print PosixPrint XPosixPrint Graph plus Print, but |
418 |
not any Cntrls |
419 |
punct PosixPunct XPosixPunct Punctuation and Symbols |
420 |
in ASCII-range; just |
421 |
punct outside it |
422 |
space PosixSpace XPosixSpace [\s\cK] |
423 |
PerlSpace XPerlSpace \s Perl's whitespace def'n |
424 |
upper PosixUpper XPosixUpper Uppercase characters |
425 |
word PosixWord XPosixWord \w Alnum + Unicode marks + |
426 |
connectors, like '_' |
427 |
(Perl extension) |
428 |
xdigit ASCII_Hex_Digit XPosixDigit Hexadecimal digit, |
429 |
ASCII-range is |
430 |
[0-9A-Fa-f] |
431 |
|
432 |
=end original |
433 |
|
434 |
----------------------------------------------------------------------- |
435 |
alnum PosixAlnum XPosixAlnum Alpha と Digit |
436 |
alpha PosixAlpha XPosixAlpha 英字 |
437 |
ascii ASCII 任意の ASCII 文字 |
438 |
blank PosixBlank XPosixBlank \h 水平空白; |
439 |
全種類は \p{HorizSpace} |
440 |
とも (GNU 拡張) |
441 |
cntrl PosixCntrl XPosixCntrl 制御文字 |
442 |
digit PosixDigit XPosixDigit \d 数字 |
443 |
graph PosixGraph XPosixGraph Alnum と Punct |
444 |
lower PosixLower XPosixLower 小文字 |
445 |
print PosixPrint XPosixPrint Graph と Print、しかし |
446 |
Cntrl は含まない |
447 |
punct PosixPunct XPosixPunct ASCII の範囲の句読点と |
448 |
シンボル; 単にその外側の |
449 |
punct |
450 |
space PosixSpace XPosixSpace [\s\cK] |
451 |
PerlSpace XPerlSpace \s Perl の空白の定義 |
452 |
upper PosixUpper XPosixUpper 大文字 |
453 |
word PosixWord XPosixWord \w Alnum + Unicode マーク + |
454 |
'_' のような接続文字 |
455 |
(Perl 拡張) |
456 |
xdigit ASCII_Hex_Digit XPosixDigit 16 進数; |
457 |
ASCII の範囲では |
458 |
[0-9A-Fa-f] |
459 |
|
460 |
=begin original |
461 |
|
462 |
Also, various synonyms like C<\p{Alpha}> for C<\p{XPosixAlpha}>; all listed |
463 |
in L<perluniprops/Properties accessible through \p{} and \P{}> |
464 |
|
465 |
=end original |
466 |
|
467 |
また、C<\p{XPosixAlpha}> のための C<\p{Alpha}> のような、さまざまな |
468 |
同義語があります; 全ての一覧は |
469 |
L<perluniprops/Properties accessible through \p{} and \P{}> にあります。 |
470 |
|
471 |
=begin original |
472 |
|
473 |
Within a character class: |
474 |
|
475 |
=end original |
476 |
|
477 |
文字クラスの中では: |
478 |
|
479 |
POSIX traditional Unicode |
480 |
[:digit:] \d \p{Digit} |
481 |
[:^digit:] \D \P{Digit} |
482 |
|
483 |
=head2 ANCHORS |
484 |
|
485 |
(アンカー) |
486 |
|
487 |
=begin original |
488 |
|
489 |
All are zero-width assertions. |
490 |
|
491 |
=end original |
492 |
|
493 |
すべてゼロ幅の表明です。 |
494 |
|
495 |
=begin original |
496 |
|
497 |
^ Match string start (or line, if /m is used) |
498 |
$ Match string end (or line, if /m is used) or before newline |
499 |
\b Match word boundary (between \w and \W) |
500 |
\B Match except at word boundary (between \w and \w or \W and \W) |
501 |
\A Match string start (regardless of /m) |
502 |
\Z Match string end (before optional newline) |
503 |
\z Match absolute string end |
504 |
\G Match where previous m//g left off |
505 |
\K Keep the stuff left of the \K, don't include it in $& |
506 |
|
507 |
=end original |
508 |
|
509 |
^ 文字列(/m が指定されている場合には行)の先頭にマッチします |
510 |
$ 文字列(/m が指定されている場合には行)の終端もしくは改行の前にマッチします |
511 |
\b 単語境界(\w と ¥W の間)にマッチします |
512 |
\B 単語境界以外(\w と \w の間か \W と \W の間)にマッチします |
513 |
\A 文字列の先頭(/m には影響されません)にマッチします |
514 |
\Z 文字列の末尾(省略可能な改行の前)にマッチします |
515 |
\z 文字列の本当の末尾にマッチします |
516 |
\G 前回の m//g のマッチした場所の末尾にマッチします |
517 |
|
518 |
=head2 QUANTIFIERS |
519 |
|
520 |
(量指定子) |
521 |
|
522 |
=begin original |
523 |
|
524 |
Quantifiers are greedy by default and match the B<longest> leftmost. |
525 |
|
526 |
=end original |
527 |
|
528 |
量指定子はデフォルトでは貪欲で、 一番左から B<一番長く> マッチします。 |
529 |
|
530 |
=begin original |
531 |
|
532 |
Maximal Minimal Possessive Allowed range |
533 |
------- ------- ---------- ------------- |
534 |
{n,m} {n,m}? {n,m}+ Must occur at least n times |
535 |
but no more than m times |
536 |
{n,} {n,}? {n,}+ Must occur at least n times |
537 |
{n} {n}? {n}+ Must occur exactly n times |
538 |
* *? *+ 0 or more times (same as {0,}) |
539 |
+ +? ++ 1 or more times (same as {1,}) |
540 |
? ?? ?+ 0 or 1 time (same as {0,1}) |
541 |
|
542 |
=end original |
543 |
|
544 |
最大 最小 所有格 範囲 |
545 |
------- ------- ---------- ------------- |
546 |
{n,m} {n,m}? {n,m}+ 最低 n 回、m 回以内出現 |
547 |
{n,} {n,}? {n,}+ 最低 n 回出現 |
548 |
{n} {n}? {n}+ 正確に n 回出現 |
549 |
* *? *+ 0 回以上 ({0,} と同じ) |
550 |
+ +? ++ 1 回以上 ({1,} と同じ) |
551 |
? ?? ?+ 0 回または 1 回 ({0,1} と同じ) |
552 |
|
553 |
=begin original |
554 |
|
555 |
The possessive forms (new in Perl 5.10) prevent backtracking: what gets |
556 |
matched by a pattern with a possessive quantifier will not be backtracked |
557 |
into, even if that causes the whole match to fail. |
558 |
|
559 |
=end original |
560 |
|
561 |
(Perl 5.10 で導入された) 所有格はバックトラックを抑制します: |
562 |
所有格量指定子が付いたパターンでマッチした場合、バックトラックはしません; |
563 |
たとえこれによってマッチ全体が失敗することになってもです。 |
564 |
|
565 |
=begin original |
566 |
|
567 |
There is no quantifier C<{,n}>. That's interpreted as a literal string. |
568 |
|
569 |
=end original |
570 |
|
571 |
C<{,n}> という量指定子はありません。 |
572 |
これはリテラルな文字列として扱われます。 |
573 |
|
574 |
=head2 EXTENDED CONSTRUCTS |
575 |
|
576 |
(拡張構造) |
577 |
|
578 |
=begin original |
579 |
|
580 |
(?#text) A comment |
581 |
(?:...) Groups subexpressions without capturing (cluster) |
582 |
(?pimsx-imsx:...) Enable/disable option (as per m// modifiers) |
583 |
(?=...) Zero-width positive lookahead assertion |
584 |
(?!...) Zero-width negative lookahead assertion |
585 |
(?<=...) Zero-width positive lookbehind assertion |
586 |
(?<!...) Zero-width negative lookbehind assertion |
587 |
(?>...) Grab what we can, prohibit backtracking |
588 |
(?|...) Branch reset |
589 |
(?<name>...) Named capture |
590 |
(?'name'...) Named capture |
591 |
(?P<name>...) Named capture (python syntax) |
592 |
(?{ code }) Embedded code, return value becomes $^R |
593 |
(??{ code }) Dynamic regex, return value used as regex |
594 |
(?N) Recurse into subpattern number N |
595 |
(?-N), (?+N) Recurse into Nth previous/next subpattern |
596 |
(?R), (?0) Recurse at the beginning of the whole pattern |
597 |
(?&name) Recurse into a named subpattern |
598 |
(?P>name) Recurse into a named subpattern (python syntax) |
599 |
(?(cond)yes|no) |
600 |
(?(cond)yes) Conditional expression, where "cond" can be: |
601 |
(?=pat) look-ahead |
602 |
(?!pat) negative look-ahead |
603 |
(?<=pat) look-behind |
604 |
(?<!pat) negative look-behind |
605 |
(N) subpattern N has matched something |
606 |
(<name>) named subpattern has matched something |
607 |
('name') named subpattern has matched something |
608 |
(?{code}) code condition |
609 |
(R) true if recursing |
610 |
(RN) true if recursing into Nth subpattern |
611 |
(R&name) true if recursing into named subpattern |
612 |
(DEFINE) always false, no no-pattern allowed |
613 |
|
614 |
=end original |
615 |
|
616 |
(?#text) コメント |
617 |
(?:...) 部分正規表現を捕捉することなくグループ化します (クラスター) |
618 |
(?imxs-imsx:...) オプションを有効/無効にする (m// 修飾子のものと同じ) |
619 |
(?=...) ゼロ幅の肯定先読み表明 |
620 |
(?!...) ゼロ幅の否定先読み表明 |
621 |
(?<=...) ゼロ幅の肯定後読み表明 |
622 |
(?<!...) ゼロ幅の否定後読み表明 |
623 |
(?>...) 出来うる限りマッチし、バックトラックしない |
624 |
(?|...) 分岐のリセット |
625 |
(?<name>...) 名前付き捕捉 |
626 |
(?'name'...) 名前付き捕捉 |
627 |
(?P<name>...) 名前付き捕捉 (python 文法) |
628 |
(?{ code }) 埋め込みコード。 戻り値は $^R に格納されます |
629 |
(??{ code }) 動的正規表現。戻り値は正規表現として扱われます |
630 |
(?N) サブパターン番号 N に再帰する |
631 |
(?-N), (?+N) N 個前/後のサブパターンに再帰する |
632 |
(?R), (?0) パターン全体の先頭に再帰する |
633 |
(?&name) 名前付きサブパターンに再帰する |
634 |
(?P>name) 名前付きサブパターンに再帰する (python 文法) |
635 |
(?(cond)yes|no) |
636 |
(?(cond)yes) 条件式; "cond" で指定できるのは: |
637 |
(?=pat) 前方参照 |
638 |
(?!pat) 前方参照の否定 |
639 |
(?<=pat) 後方参照 |
640 |
(?<!pat) 後方参照の否定 |
641 |
(N) サブパターン N が何かにマッチした |
642 |
(<name>) 名前付きサブルーチンが何かにマッチした |
643 |
('name') 名前付きサブルーチンが何かにマッチした |
644 |
(?{code}) コード条件 |
645 |
(R) 再帰したら真 |
646 |
(RN) N 番目のサブパターンに再帰したら真 |
647 |
(R&name) 名前付きサブパターンに再帰したら真 |
648 |
(DEFINE) 常に偽; パターンなしは許されない |
649 |
|
650 |
=head2 VARIABLES |
651 |
|
652 |
(変数) |
653 |
|
654 |
=begin original |
655 |
|
656 |
$_ Default variable for operators to use |
657 |
|
658 |
=end original |
659 |
|
660 |
$_ 演算子が使用するデフォルトの変数 |
661 |
|
662 |
=begin original |
663 |
|
664 |
$` Everything prior to matched string |
665 |
$& Entire matched string |
666 |
$' Everything after to matched string |
667 |
|
668 |
=end original |
669 |
|
670 |
$` マッチした文字列に先行する部分 |
671 |
$& マッチした文字列全体 |
672 |
$' マッチした文字列に後続する部分 |
673 |
|
674 |
=begin original |
675 |
|
676 |
${^PREMATCH} Everything prior to matched string |
677 |
${^MATCH} Entire matched string |
678 |
${^POSTMATCH} Everything after to matched string |
679 |
|
680 |
=end original |
681 |
|
682 |
${^PREMATCH} マッチした文字列に先行する部分 |
683 |
${^MATCH} マッチした文字列全体 |
684 |
${^POSTMATCH} マッチした文字列に後続する部分 |
685 |
|
686 |
=begin original |
687 |
|
688 |
Note to those still using Perl 5.18 or earlier: |
689 |
The use of C<$`>, C<$&> or C<$'> will slow down B<all> regex use |
690 |
within your program. Consult L<perlvar> for C<@-> |
691 |
to see equivalent expressions that won't cause slow down. |
692 |
See also L<Devel::SawAmpersand>. Starting with Perl 5.10, you |
693 |
can also use the equivalent variables C<${^PREMATCH}>, C<${^MATCH}> |
694 |
and C<${^POSTMATCH}>, but for them to be defined, you have to |
695 |
specify the C</p> (preserve) modifier on your regular expression. |
696 |
In Perl 5.20, the use of C<$`>, C<$&> and C<$'> makes no speed difference. |
697 |
|
698 |
=end original |
699 |
|
700 |
まだ Perl 5.18 以前を使っている場合の注意: |
701 |
C<$`>, C<$&>, C<$'> のいずれかを使うと、プログラム中の B<全ての> 正規表現の |
702 |
速度が低下します。 |
703 |
速度低下を引き起こさない、等価な表現のためには、L<perlvar> の C<@-> を |
704 |
調べてみてください。 |
705 |
また、L<Devel::SawAmpersand> も参照してください。 |
706 |
Perl 5.10 から、等価な変数である C<${^PREMATCH}>, C<${^MATCH}>, |
707 |
C<${^POSTMATCH}> も使えますが、これらが定義されるには、正規表現に |
708 |
C</p> (保存(preserve)) 修飾子をつける必要があります。 |
709 |
Perl 5.20 では、C<$`>, C<$&>, C<$'> を使っても速度の違いはありません。 |
710 |
|
711 |
=begin original |
712 |
|
713 |
$1, $2 ... hold the Xth captured expr |
714 |
$+ Last parenthesized pattern match |
715 |
$^N Holds the most recently closed capture |
716 |
$^R Holds the result of the last (?{...}) expr |
717 |
@- Offsets of starts of groups. $-[0] holds start of whole match |
718 |
@+ Offsets of ends of groups. $+[0] holds end of whole match |
719 |
%+ Named capture groups |
720 |
%- Named capture groups, as array refs |
721 |
|
722 |
=end original |
723 |
|
724 |
$1, $2 ... X 番目の捕捉された式を保持します |
725 |
$+ 最後にかっこで囲まれたパターンマッチ |
726 |
$^N 最も近くに閉じた捕捉を保持します |
727 |
$^R 最後の (?{...}) 式の結果を保持します |
728 |
@- グループの先頭からのオフセット。 $-[0] はマッチ全体の先頭です |
729 |
@+ グループの末尾からのオフセット。 $+[0] はマッチ全体の末尾です |
730 |
%+ 名前付き捕捉グループ |
731 |
%- 配列リファレンスとしての名前付き捕捉グループ |
732 |
|
733 |
=begin original |
734 |
|
735 |
Captured groups are numbered according to their I<opening> paren. |
736 |
|
737 |
=end original |
738 |
|
739 |
捕捉したグループは I<開き> かっこの順番で番号付けされます。 |
740 |
|
741 |
=head2 FUNCTIONS |
742 |
|
743 |
(関数) |
744 |
|
745 |
=begin original |
746 |
|
747 |
lc Lowercase a string |
748 |
lcfirst Lowercase first char of a string |
749 |
uc Uppercase a string |
750 |
ucfirst Titlecase first char of a string |
751 |
fc Foldcase a string |
752 |
|
753 |
=end original |
754 |
|
755 |
lc 文字列を小文字にします |
756 |
lcfirst 文字列の最初の文字を小文字にします |
757 |
uc 文字列を大文字にします |
758 |
ucfirst 文字列の最初の文字を Titlecase にします |
759 |
fc 文字列を畳み込み文字にします |
760 |
|
761 |
=begin original |
762 |
|
763 |
pos Return or set current match position |
764 |
quotemeta Quote metacharacters |
765 |
reset Reset ?pattern? status |
766 |
study Analyze string for optimizing matching |
767 |
|
768 |
=end original |
769 |
|
770 |
pos カレントのマッチ位置を返したり設定したりします |
771 |
quotemeta メタ文字をクォートします |
772 |
reset ?pattern? の状態をリセットします |
773 |
study マッチングの最適化のために文字列を調べます |
774 |
|
775 |
=begin original |
776 |
|
777 |
split Use a regex to split a string into parts |
778 |
|
779 |
=end original |
780 |
|
781 |
split 文字列を分割するために正規表現を使います |
782 |
|
783 |
=begin original |
784 |
|
785 |
The first five of these are like the escape sequences C<\L>, C<\l>, |
786 |
C<\U>, C<\u>, and C<\F>. For Titlecase, see L</Titlecase>; For |
787 |
Foldcase, see L</Foldcase>. |
788 |
|
789 |
=end original |
790 |
|
791 |
これらの最初の五つは、エスケープシーケンス C<\L>, C<\l>, C<\U>, C<\u>, |
792 |
C<\F> と似ています。 |
793 |
タイトル文字については、L</Titlecase> を参照してください; |
794 |
畳み込み文字については、L</Foldcase> を参照してください。 |
795 |
|
796 |
=head2 TERMINOLOGY |
797 |
|
798 |
(用語) |
799 |
|
800 |
=head3 Titlecase |
801 |
|
802 |
(タイトル文字) |
803 |
|
804 |
=begin original |
805 |
|
806 |
Unicode concept which most often is equal to uppercase, but for |
807 |
certain characters like the German "sharp s" there is a difference. |
808 |
|
809 |
=end original |
810 |
|
811 |
Unicode の概念で、ほとんどの場合は大文字と同じですが、ドイツ語の |
812 |
"sharp s" のような特定の文字については異なります。 |
813 |
|
814 |
=head3 Foldcase |
815 |
|
816 |
(畳み込み文字) |
817 |
|
818 |
=begin original |
819 |
|
820 |
Unicode form that is useful when comparing strings regardless of case, |
821 |
as certain characters have complex one-to-many case mappings. Primarily a |
822 |
variant of lowercase. |
823 |
|
824 |
=end original |
825 |
|
826 |
大文字小文字に関わらず文字列を比較するときに有用な Unicode の形式です; |
827 |
ある種の文字は複雑な 1 対多大文字小文字マッピングを持つからです。 |
828 |
主に小文字の変種です。 |
829 |
|
830 |
=head1 AUTHOR |
831 |
|
832 |
Iain Truskett. Updated by the Perl 5 Porters. |
833 |
|
834 |
This document may be distributed under the same terms as Perl itself. |
835 |
|
836 |
=head1 SEE ALSO |
837 |
|
838 |
=over 4 |
839 |
|
840 |
=item * |
841 |
|
842 |
=begin original |
843 |
|
844 |
L<perlretut> for a tutorial on regular expressions. |
845 |
|
846 |
=end original |
847 |
|
848 |
正規表現のチュートリアルである L<perlretut>。 |
849 |
|
850 |
=item * |
851 |
|
852 |
=begin original |
853 |
|
854 |
L<perlrequick> for a rapid tutorial. |
855 |
|
856 |
=end original |
857 |
|
858 |
手っ取り早いチュートリアルである L<perlrequick>。 |
859 |
|
860 |
=item * |
861 |
|
862 |
=begin original |
863 |
|
864 |
L<perlre> for more details. |
865 |
|
866 |
=end original |
867 |
|
868 |
さらなる詳細である L<perlre>。 |
869 |
|
870 |
=item * |
871 |
|
872 |
=begin original |
873 |
|
874 |
L<perlvar> for details on the variables. |
875 |
|
876 |
=end original |
877 |
|
878 |
変数に関する詳細である L<perlvar>。 |
879 |
|
880 |
=item * |
881 |
|
882 |
=begin original |
883 |
|
884 |
L<perlop> for details on the operators. |
885 |
|
886 |
=end original |
887 |
|
888 |
演算子の詳細である L<perlop>。 |
889 |
|
890 |
=item * |
891 |
|
892 |
=begin original |
893 |
|
894 |
L<perlfunc> for details on the functions. |
895 |
|
896 |
=end original |
897 |
|
898 |
関数の詳細である L<perlfunc>。 |
899 |
|
900 |
=item * |
901 |
|
902 |
=begin original |
903 |
|
904 |
L<perlfaq6> for FAQs on regular expressions. |
905 |
|
906 |
=end original |
907 |
|
908 |
正規表現に関する FAQ である L<perlfaq6>。 |
909 |
|
910 |
=item * |
911 |
|
912 |
=begin original |
913 |
|
914 |
L<perlrebackslash> for a reference on backslash sequences. |
915 |
|
916 |
=end original |
917 |
|
918 |
バックスラッシュシーケンス の参考資料である L<perlrebackslash>。 |
919 |
|
920 |
=item * |
921 |
|
922 |
=begin original |
923 |
|
924 |
L<perlrecharclass> for a reference on character classes. |
925 |
|
926 |
=end original |
927 |
|
928 |
文字クラスの参考資料である L<perlrecharclass>。 |
929 |
|
930 |
=item * |
931 |
|
932 |
=begin original |
933 |
|
934 |
The L<re> module to alter behaviour and aid |
935 |
debugging. |
936 |
|
937 |
=end original |
938 |
|
939 |
振る舞いの変更とデバッグの補助のための L<re> モジュール。 |
940 |
|
941 |
=item * |
942 |
|
943 |
L<perldebug/"Debugging Regular Expressions"> |
944 |
|
945 |
=item * |
946 |
|
947 |
=begin original |
948 |
|
949 |
L<perluniintro>, L<perlunicode>, L<charnames> and L<perllocale> |
950 |
for details on regexes and internationalisation. |
951 |
|
952 |
=end original |
953 |
|
954 |
正規表現や国際化に関する詳細である L<perluniintro>, L<perlunicode>, |
955 |
L<charnames>, L<perllocale>。 |
956 |
|
957 |
=item * |
958 |
|
959 |
=begin original |
960 |
|
961 |
I<Mastering Regular Expressions> by Jeffrey Friedl |
962 |
(F<http://oreilly.com/catalog/9780596528126/>) for a thorough grounding and |
963 |
reference on the topic. |
964 |
|
965 |
=end original |
966 |
|
967 |
この話題に関する完全な背景と参考資料である |
968 |
Jeffrey Friedl による書籍 I<Mastering Regular Expressions> |
969 |
(F<http://oreilly.com/catalog/9780596528126/>) |
970 |
(O'Reillyから出版: ISBN 1556592-257-3) |
971 |
(日本語版は「詳説 正規表現」ISBN4-87311-130-7 (第二版のもの))。 |
972 |
|
973 |
=back |
974 |
|
975 |
=head1 THANKS |
976 |
|
977 |
David P.C. Wollmann, |
978 |
Richard Soderberg, |
979 |
Sean M. Burke, |
980 |
Tom Christiansen, |
981 |
Jim Cromie, |
982 |
and |
983 |
Jeffrey Goff |
984 |
for useful advice. |
985 |
|
986 |
=cut |
987 |
|
988 |
=begin meta |
989 |
|
990 |
Translate: KIMURA Koichi |
991 |
Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.0-) |
992 |
Status: completed |
993 |
|
994 |
=end meta |
995 |
|