/
perlrebackslash.pod
1817 lines (1293 loc) · 59.6 KB
/
perlrebackslash.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=encoding euc-jp
=head1 NAME
=begin original
perlrebackslash - Perl Regular Expression Backslash Sequences and Escapes
=end original
perlrebackslash - Perl 正規表現逆スラッシュシーケンスとエスケープ
=head1 DESCRIPTION
=begin original
The top level documentation about Perl regular expressions
is found in L<perlre>.
=end original
Perl 正規表現に関する最上位文書は L<perlre> です。
=begin original
This document describes all backslash and escape sequences. After
explaining the role of the backslash, it lists all the sequences that have
a special meaning in Perl regular expressions (in alphabetical order),
then describes each of them.
=end original
この文書は全ての逆スラッシュシーケンスとエスケープシーケンスについて
記述します。
逆スラッシュの役割について説明したあと、Perl 正規表現の中で特別な意味を持つ
全てのシーケンスを(アルファベット順に)示し、それぞれについて記述します。
=begin original
Most sequences are described in detail in different documents; the primary
purpose of this document is to have a quick reference guide describing all
backslash and escape sequences.
=end original
ほとんどのシーケンスは他の文書に詳細に記述されています; この文書の主な目的は
全ての逆スラッシュシーケンスとエスケープシーケンスを記述した
クイックリファレンスガイドとなることです。
=head2 The backslash
(逆スラッシュ)
=begin original
In a regular expression, the backslash can perform one of two tasks:
it either takes away the special meaning of the character following it
(for instance, C<\|> matches a vertical bar, it's not an alternation),
or it is the start of a backslash or escape sequence.
=end original
正規表現において、逆スラッシュは二つのタスクのどちらかを行います:
引き続く文字の特殊な意味を取り除く(例えば、(C<\|> は代替ではなく、垂直バーに
マッチングします)か、逆スラッシュシーケンスまたはエスケープシーケンスの
開始となります。
=begin original
The rules determining what it is are quite simple: if the character
following the backslash is an ASCII punctuation (non-word) character (that is,
anything that is not a letter, digit, or underscore), then the backslash just
takes away any special meaning of the character following it.
=end original
これが何かを決定する規則はかなり単純です: 逆スラッシュに引き続く文字が
ASCII 句読点(非単語)文字(これは英字、数字、下線以外の全ての文字)なら、
逆スラッシュは引き続く文字の特別な意味を取り除きます。
=begin original
If the character following the backslash is an ASCII letter or an ASCII digit,
then the sequence may be special; if so, it's listed below. A few letters have
not been used yet, so escaping them with a backslash doesn't change them to be
special. A future version of Perl may assign a special meaning to them, so if
you have warnings turned on, Perl issues a warning if you use such a
sequence. [1].
=end original
逆スラッシュに引き続く文字が ASCII 英字または ASCII 数字なら、この並びは
特別です; その場合、以下に示します。
いくつかの文字はまだ使われておらず、これを逆スラッシュでエスケープするのは
特別なものにはしません。
将来のバージョンの Perl はこれに特別な意味を割り当てるかもしれないので、
しかし、警告が有効なら、そのような並びを使うと Perl は警告を出力します。
[1]。
=begin original
It is however guaranteed that backslash or escape sequences never have a
punctuation character following the backslash, not now, and not in a future
version of Perl 5. So it is safe to put a backslash in front of a non-word
character.
=end original
しかし、逆スラッシュシーケンスやエスケープシーケンスが逆スラッシュの後に
句読点文字がくることがないことは今だけではなく将来のバージョンの
Perl 5 でも保証されています。
従って、非単語文字の前に逆スラッシュを置くのは安全です。
=begin original
Note that the backslash itself is special; if you want to match a backslash,
you have to escape the backslash with a backslash: C</\\/> matches a single
backslash.
=end original
逆スラッシュ自体が特別であることに注意してください; 逆スラッシュと
マッチングしたいなら、逆スラッシュを逆スラッシュでエスケープする必要が
あります: C</\\/> は単一の逆スラッシュにマッチングします。
=over 4
=item [1]
=begin original
There is one exception. If you use an alphanumeric character as the
delimiter of your pattern (which you probably shouldn't do for readability
reasons), you have to escape the delimiter if you want to match
it. Perl won't warn then. See also L<perlop/Gory details of parsing
quoted constructs>.
=end original
一つの例外があります。
パターンの区切りとして英数字を使っている(おそらくこれは可読性の理由で
するべきではありません)場合、その文字にマッチングしたいなら区切り文字を
エスケープする必要があります。
Perl は警告を出しません。
L<perlop/Gory details of parsing quoted constructs> も参照してください。
=back
=head2 All the sequences and escapes
(全てのシーケンスとエスケープ)
=begin original
Those not usable within a bracketed character class (like C<[\da-z]>) are marked
as C<Not in [].>
=end original
(C<[\da-z]> のような) 大かっこ文字クラスで使えないものは
C<[] 内では使えない。> と記しています。
=begin original
\000 Octal escape sequence. See also \o{}.
\1 Absolute backreference. Not in [].
\a Alarm or bell.
\A Beginning of string. Not in [].
\b{}, \b Boundary. (\b is a backspace in []).
\B{}, \B Not a boundary. Not in [].
\cX Control-X.
\d Match any digit character.
\D Match any character that isn't a digit.
\e Escape character.
\E Turn off \Q, \L and \U processing. Not in [].
\f Form feed.
\F Foldcase till \E. Not in [].
\g{}, \g1 Named, absolute or relative backreference.
Not in [].
\G Pos assertion. Not in [].
\h Match any horizontal whitespace character.
\H Match any character that isn't horizontal whitespace.
\k{}, \k<>, \k'' Named backreference. Not in [].
\K Keep the stuff left of \K. Not in [].
\l Lowercase next character. Not in [].
\L Lowercase till \E. Not in [].
\n (Logical) newline character.
\N Match any character but newline. Not in [].
\N{} Named or numbered (Unicode) character or sequence.
\o{} Octal escape sequence.
\p{}, \pP Match any character with the given Unicode property.
\P{}, \PP Match any character without the given property.
\Q Quote (disable) pattern metacharacters till \E. Not
in [].
\r Return character.
\R Generic new line. Not in [].
\s Match any whitespace character.
\S Match any character that isn't a whitespace.
\t Tab character.
\u Titlecase next character. Not in [].
\U Uppercase till \E. Not in [].
\v Match any vertical whitespace character.
\V Match any character that isn't vertical whitespace
\w Match any word character.
\W Match any character that isn't a word character.
\x{}, \x00 Hexadecimal escape sequence.
\X Unicode "extended grapheme cluster". Not in [].
\z End of string. Not in [].
\Z End of string. Not in [].
=end original
\000 8 進数エスケープシーケンス。\o{} も参照。
\1 絶対後方参照。[] 内では使えない。
\a アラームまたはベル。
\A 文字列の先頭。[] 内では使えない。
\b{}, \b 境界。(\b は [] 内では後退)。
\B{}, \B 境界でない。[] 内では使えない。
\cX Control-X。
\d 数字にマッチング。
\D 数字以外にマッチング。
\e エスケープ文字。
\E \Q, \L, \U の処理を終了する。[] 内では使えない。
\f 書式送り。
\F \E まで畳み込み文字。[] 内では使えない。
\g{}, \g1 名前付きの絶対または相対後方参照。[] 内では使えない。
\G 位置表明。[] 内では使えない。
\h 水平空白にマッチング。
\H 水平空白以外にマッチング。
\k{}, \k<>, \k'' 名前付き後方参照。[] 内では使えない。
\K \K の左側を保持する。[] 内では使えない。
\l 次の文字を小文字に。[] 内では使えない。
\L \E まで小文字に。[] 内では使えない。
\n (論理) 改行文字。
\N 改行以外にマッチング。[] 内では使えない。
\N{} 名前付きまたは番号 (Unicode) 文字または並び。
\o{} 8 進数エスケープシーケンス。
\p{}, \pP 指定された Unicode 特性を持つ文字にマッチング。
\P{}, \PP 指定された Unicode 特性を持たない文字にマッチング。
\Q \E までパターンメタ文字をクォート(無効化)。
[] 内では使えない。
\r 復帰文字。
\R 一般的な改行。[] 内では使えない。
\s 空白文字にマッチング。
\S 空白文字以外にマッチング。
\t タブ文字。
\u 辻の文字をタイトル文字に。[] 内では使えない。
\U \E まで大文字に。[] 内では使えない。
\v 垂直空白にマッチング。
\V 垂直空白以外にマッチング。
\w 単語文字にマッチング。
\W 単語文字以外にマッチング。
\x{}, \x00 16 進数エスケープシーケンス。
\X 「拡張書記素クラスタ」。[] 内では使えない。
\z 文字列の末尾。[] 内では使えない。
\Z 文字列の末尾。[] 内では使えない。
=head2 Character Escapes
(文字エスケープ)
=head3 Fixed characters
(固定文字)
=begin original
A handful of characters have a dedicated I<character escape>. The following
table shows them, along with their ASCII code points (in decimal and hex),
their ASCII name, the control escape on ASCII platforms and a short
description. (For EBCDIC platforms, see L<perlebcdic/OPERATOR DIFFERENCES>.)
=end original
一部の文字列は I<文字エスケープ> として動作します。
これらは、ASCII 符号位置 (10 進と 16 進)、ASCII の名前、ASCII
プラットフォームでの制御エスケープ、短い説明と共に、以下の表に示しています。
(EBCDIC プラットフォームについては、L<perlebcdic/OPERATOR DIFFERENCES> を
参照してください。)
=begin original
Seq. Code Point ASCII Cntrl Description.
Dec Hex
\a 7 07 BEL \cG alarm or bell
\b 8 08 BS \cH backspace [1]
\e 27 1B ESC \c[ escape character
\f 12 0C FF \cL form feed
\n 10 0A LF \cJ line feed [2]
\r 13 0D CR \cM carriage return
\t 9 09 TAB \cI tab
=end original
Seq. 符号位置 ASCII Cntrl 説明。
10 進 16 進
\a 7 07 BEL \cG アラームまたはベル
\b 8 08 BS \cH 後退 [1]
\e 27 1B ESC \c[ エスケープ文字
\f 12 0C FF \cL 書式送り
\n 10 0A LF \cJ 改行 [2]
\r 13 0D CR \cM 復帰
\t 9 09 TAB \cI タブ
=over 4
=item [1]
=begin original
C<\b> is the backspace character only inside a character class. Outside a
character class, C<\b> alone is a word-character/non-word-character
boundary, and C<\b{}> is some other type of boundary.
=end original
C<\b> は文字クラスの中でのみ復帰文字です。
文字クラスの外側では、C<\b> 単独はは単語文字/非単語文字境界で、
C<\b{}> は他の種類の境界です。
=item [2]
=begin original
C<\n> matches a logical newline. Perl converts between C<\n> and your
OS's native newline character when reading from or writing to text files.
=end original
C<\n> は論理改行にマッチングします。
Perl はテキストファイルの読み書きをする時には C<\n> OS ネイティブな
改行文字との間を変換します。
=back
=head4 Example
(例)
$str =~ /\t/; # Matches if $str contains a (horizontal) tab.
=head3 Control characters
(制御文字)
=begin original
C<\c> is used to denote a control character; the character following C<\c>
determines the value of the construct. For example the value of C<\cA> is
C<chr(1)>, and the value of C<\cb> is C<chr(2)>, etc.
The gory details are in L<perlop/"Regexp Quote-Like Operators">. A complete
list of what C<chr(1)>, etc. means for ASCII and EBCDIC platforms is in
L<perlebcdic/OPERATOR DIFFERENCES>.
=end original
C<\c> は制御文字を示すために使われます; C<\c> に引き続く文字は
構文の値を決定します。
例えば C<\cA> の値は C<chr(1)>、C<\cb> の値は C<chr(2)>、などです。
内部の詳細は L<perlop/"Regexp Quote-Like Operators"> にあります。
ASCII と EBCDIC プラットフォームで C<chr(1)> などが意味するものの完全な
一覧は L<perlebcdic/OPERATOR DIFFERENCES> にあります。
=begin original
Note that C<\c\> alone at the end of a regular expression (or doubled-quoted
string) is not valid. The backslash must be followed by another character.
That is, C<\c\I<X>> means C<chr(28) . 'I<X>'> for all characters I<X>.
=end original
正規表現 (またはダブルクォートされた文字列) の末尾に単体で C<\c\> を置くのは
不正です。
逆スラッシュには他の文字が引き続かなければなりません。
つまり、全ての文字 I<X> に対して C<\c\I<X>> は C<chr(28) . 'I<X>' を意味する>
ということです。
=begin original
To write platform-independent code, you must use C<\N{I<NAME>}> instead, like
C<\N{ESCAPE}> or C<\N{U+001B}>, see L<charnames>.
=end original
プラットフォーム独立なコードを書くためには、代わりに C<\N{ESCAPE}> や
C<\N{U+001B}> のような C<\N{I<NAME>}> を使わなければなりません;
L<charnames> を参照してください。
=begin original
Mnemonic: I<c>ontrol character.
=end original
記憶法: 制御文字(I<c>ontrol character)。
=head4 Example
(例)
$str =~ /\cK/; # Matches if $str contains a vertical tab (control-K).
=head3 Named or numbered characters and character sequences
(名前付きまたは番号による文字および文字並び)
=begin original
Unicode characters have a Unicode name and numeric code point (ordinal)
value. Use the
C<\N{}> construct to specify a character by either of these values.
Certain sequences of characters also have names.
=end original
Unicode 文字は Unicode 名と数値の符号位置(序数)を持ちます。
文字をそれらの値で指定するには C<\N{}> 構文を使います。
一部の文字並びにも名前があります。
=begin original
To specify by name, the name of the character or character sequence goes
between the curly braces.
=end original
名前を指定するには、文字や文字並びの名前は中かっこの間に書きます。
=begin original
To specify a character by Unicode code point, use the form C<\N{U+I<code
point>}>, where I<code point> is a number in hexadecimal that gives the
code point that Unicode has assigned to the desired character. It is
customary but not required to use leading zeros to pad the number to 4
digits. Thus C<\N{U+0041}> means C<LATIN CAPITAL LETTER A>, and you will
rarely see it written without the two leading zeros. C<\N{U+0041}> means
"A" even on EBCDIC machines (where the ordinal value of "A" is not 0x41).
=end original
文字を Unicode 符号位置で指定するには、C<\N{U+I<code point>}> 形式を使います;
ここで I<code point> は Unicode が目的の文字に割り当てている符号位置を
16 進数で指定します。
数値を 4 桁にパッディングするために先頭にゼロを付ける慣習がありますが、
必須ではありません。
従って C<\N{U+0041}> は C<LATIN CAPITAL LETTER A> を意味し、先頭の二つの
ゼロなしで書かれるのを見ることは稀でしょう。
C<\N{U+0041}> は ("A" の序数が 0x41 でない) EBCDIC マシンでも "A" を
意味します。
=begin original
It is even possible to give your own names to characters and character
sequences by using the L<charnames> module. These custom names are
lexically scoped, and so a given code point may have different names
in different scopes. The name used is what is in effect at the time the
C<\N{}> is expanded. For patterns in double-quotish context, that means
at the time the pattern is parsed. But for patterns that are delimitted
by single quotes, the expansion is deferred until pattern compilation
time, which may very well have a different C<charnames> translator in
effect.
=end original
L<charnames> モジュールを使って
文字や文字並びに独自の名前をつけることすら可能です。
これらのカスタム名はレキシカルスコープなので、
指定された符号位置は、異なるスコープでは異なる名前かも知れません。
使われる名前は、C<\N{}> が展開された時点で有効なものです。
ダブルクォート風コンテキストのパターンでは、
これはパターンがパースされた時点を意味します。
しかし、シングルクォートで区切られたパターンの場合、
展開はパターンのコンパイル島で遅延されるので、
異なった C<charnames> 変換器を持っているかもしれません。
=begin original
(There is an expanded internal form that you may see in debug output:
C<\N{U+I<code point>.I<code point>...}>.
The C<...> means any number of these I<code point>s separated by dots.
This represents the sequence formed by the characters. This is an internal
form only, subject to change, and you should not try to use it yourself.)
=end original
(デバッグ出力で見るかも知れない拡張内部形式
C<\N{U+I<code point>.I<code point>...}> があります。
C<...> は任意の数の I<code point> をドットで区切ったものです。
これは文字によって形成される並びを表現します。
これは内部形式専用で、変更されるかも知れず、自分自身で
使おうとするべきではありません。)
=begin original
Mnemonic: I<N>amed character.
=end original
記憶法: 名前付き文字(I<N>amed character)。
=begin original
Note that a character or character sequence expressed as a named
or numbered character is considered a character without special
meaning by the regex engine, and will match "as is".
=end original
名前付きまたは番号による文字または文字並びで表現される文字は
正規表現エンジンにとって特別な意味を持たない文字として扱われ、
「そのまま」でマッチングすることに注意してください。
=head4 Example
(例)
$str =~ /\N{THAI CHARACTER SO SO}/; # Matches the Thai SO SO character
use charnames 'Cyrillic'; # Loads Cyrillic names.
$str =~ /\N{ZHE}\N{KA}/; # Match "ZHE" followed by "KA".
=head3 Octal escapes
(8 進数エスケープ)
=begin original
There are two forms of octal escapes. Each is used to specify a character by
its code point specified in octal notation.
=end original
8 進数エスケープには二つの形式があります。
それぞれは 8 進記法で指定された符号位置で文字を指定するために使われます。
=begin original
One form, available starting in Perl 5.14 looks like C<\o{...}>, where the dots
represent one or more octal digits. It can be used for any Unicode character.
=end original
Perl 5.14 から利用可能になった一つ目の形式は C<\o{...}> のようなもので、
ドットは一つ以上の 8 進数を表現します。
これはどのような Unicode 文字にも使えます。
=begin original
It was introduced to avoid the potential problems with the other form,
available in all Perls. That form consists of a backslash followed by three
octal digits. One problem with this form is that it can look exactly like an
old-style backreference (see
L</Disambiguation rules between old-style octal escapes and backreferences>
below.) You can avoid this by making the first of the three digits always a
zero, but that makes \077 the largest code point specifiable.
=end original
これは全ての Perl で利用可能なもう一つの形式の潜在的な問題を避けるために
導入されました。
この形式は逆スラッシュに引き続いて 3 桁の 8 進数です。
この形式の問題の一つは、古い形式の後方参照とまったく同じように見えることです
(以下の
L</Disambiguation rules between old-style octal escapes and backreferences>
を参照してください。)
3 桁の数字の最初の文字を常にゼロにすることにこれを避けられますが、指定できる
最大の符号位置が \077 になります。
=begin original
In some contexts, a backslash followed by two or even one octal digits may be
interpreted as an octal escape, sometimes with a warning, and because of some
bugs, sometimes with surprising results. Also, if you are creating a regex
out of smaller snippets concatenated together, and you use fewer than three
digits, the beginning of one snippet may be interpreted as adding digits to the
ending of the snippet before it. See L</Absolute referencing> for more
discussion and examples of the snippet problem.
=end original
ある種のコンテキストでは、逆スラッシュに引き続いて二つや一つの 8 進数が
8 進エスケープとして解釈され、時々警告が出て、ある種のバグにより、時々
驚くような結果になります。
また、より小さいスニペットを結合して正規表現を作成して、3 桁より小さいものを
使うと、一つのスニペットの最初がその前のスニペットの終わりに追加された
数値と解釈されることがあります。
スニペット問題に関するさらなる議論と例については L</Absolute referencing> を
参照してください。
=begin original
Note that a character expressed as an octal escape is considered
a character without special meaning by the regex engine, and will match
"as is".
=end original
8 進エスケープで表現される文字は正規表現エンジンにとって特別な意味を持たない
文字として考えられ、「そのまま」でマッチングすることに注意してください。
=begin original
To summarize, the C<\o{}> form is always safe to use, and the other form is
safe to use for code points through \077 when you use exactly three digits to
specify them.
=end original
まとめると、C<\o{}> 形式は常に安全で、もう一つの形式は、指定するときに
正確に 3 桁を使う場合 \077 までの符号位置なら安全です。
=begin original
Mnemonic: I<0>ctal or I<o>ctal.
=end original
記憶法: 8 進数(I<0>ctal または I<o>ctal)。
=head4 Examples (assuming an ASCII platform)
(例(ASCII プラットフォームを仮定))
$str = "Perl";
$str =~ /\o{120}/; # Match, "\120" is "P".
$str =~ /\120/; # Same.
$str =~ /\o{120}+/; # Match, "\120" is "P",
# it's repeated at least once.
$str =~ /\120+/; # Same.
$str =~ /P\053/; # No match, "\053" is "+" and taken literally.
/\o{23073}/ # Black foreground, white background smiling face.
/\o{4801234567}/ # Raises a warning, and yields chr(4).
=head4 Disambiguation rules between old-style octal escapes and backreferences
(古い形式の 8 進エスケープと後方参照との曖昧さをなくす規則)
=begin original
Octal escapes of the C<\000> form outside of bracketed character classes
potentially clash with old-style backreferences (see L</Absolute referencing>
below). They both consist of a backslash followed by numbers. So Perl has to
use heuristics to determine whether it is a backreference or an octal escape.
Perl uses the following rules to disambiguate:
=end original
大かっこ文字クラスの外側での C<\000> 形式での 8 進エスケープは潜在的に
古い形式の後方参照を破壊します (後述の L</Absolute referencing> 参照)。
これらはどちらも逆スラッシュに引き続く数値で構成されます。
それで Perl は後方参照か 8 進エスケープかを決定するのに発見的手法を
使います。
Perl は曖昧さをなくすために以下の規則を使います:
=over 4
=item 1
=begin original
If the backslash is followed by a single digit, it's a backreference.
=end original
逆スラッシュに引き続くのが単一の数字なら、それは後方参照です。
=item 2
=begin original
If the first digit following the backslash is a 0, it's an octal escape.
=end original
逆スラッシュに引き続く文字が 0 なら、それは 8 進エスケープです。
=item 3
=begin original
If the number following the backslash is N (in decimal), and Perl already
has seen N capture groups, Perl considers this a backreference. Otherwise,
it considers it an octal escape. If N has more than three digits, Perl
takes only the first three for the octal escape; the rest are matched as is.
=end original
逆スラッシュに引き続く数値が N (10 進) で、Perl がすでに N 個の
捕捉グループを見ているなら、Perl はこれを後方参照として扱います。
さもなければ、これは 8 進エスケープとして扱います。
N が 3 桁より長いなら、Perl は 8 進エスケープとして最初の 3 桁のみを
使います; 残りはそのままマッチングされます。
my $pat = "(" x 999;
$pat .= "a";
$pat .= ")" x 999;
/^($pat)\1000$/; # Matches 'aa'; there are 1000 capture groups.
/^$pat\1000$/; # Matches 'a@0'; there are 999 capture groups
# and \1000 is seen as \100 (a '@') and a '0'.
=back
=begin original
You can force a backreference interpretation always by using the C<\g{...}>
form. You can the force an octal interpretation always by using the C<\o{...}>
form, or for numbers up through \077 (= 63 decimal), by using three digits,
beginning with a "0".
=end original
常に C<\g{...}> 形式を使うことで後方参照に解釈するように強制できます。
常に C<\o{...}> 形式を使うか、\077 (= 10 進で 63) までの数値の場合は、
"0" を先頭に付けて常に 3 桁で使うことで 8 進数に解釈するように強制できます。
=head3 Hexadecimal escapes
(16 進数エスケープ)
=begin original
Like octal escapes, there are two forms of hexadecimal escapes, but both start
with the sequence C<\x>. This is followed by either exactly two hexadecimal
digits forming a number, or a hexadecimal number of arbitrary length surrounded
by curly braces. The hexadecimal number is the code point of the character you
want to express.
=end original
8 進エスケープと同様、16 進エスケープにも二つの形式がありますが、どちらも
並び C<\x> で始まります。
これに正確に 2 桁の数値を形成する 16 進数、あるいは中かっこで囲まれた
任意の桁の 16 進数が引き続きます。
16 進数は表現したい文字の符号位置です。
=begin original
Note that a character expressed as one of these escapes is considered a
character without special meaning by the regex engine, and will match
"as is".
=end original
これらのエスケープの一つでで表現される文字は正規表現エンジンにとって特別な
意味を持たない文字として考えられ、「そのまま」でマッチングすることに
注意してください。
=begin original
Mnemonic: heI<x>adecimal.
=end original
記憶法: 16 進数(heI<x>adecimal)。
=head4 Examples (assuming an ASCII platform)
(例(ASCII プラットフォームを仮定))
$str = "Perl";
$str =~ /\x50/; # Match, "\x50" is "P".
$str =~ /\x50+/; # Match, "\x50" is "P", it is repeated at least once
$str =~ /P\x2B/; # No match, "\x2B" is "+" and taken literally.
/\x{2603}\x{2602}/ # Snowman with an umbrella.
# The Unicode character 2603 is a snowman,
# the Unicode character 2602 is an umbrella.
/\x{263B}/ # Black smiling face.
/\x{263b}/ # Same, the hex digits A - F are case insensitive.
=head2 Modifiers
(修飾子)
=begin original
A number of backslash sequences have to do with changing the character,
or characters following them. C<\l> will lowercase the character following
it, while C<\u> will uppercase (or, more accurately, titlecase) the
character following it. They provide functionality similar to the
functions C<lcfirst> and C<ucfirst>.
=end original
多くの逆スラッシュシーケンスは、引き続く文字を変更します。
C<\l> は引き続く文字を小文字に変えます; 一方C<\u> は引き続く文字を大文字(より
正確にはタイトル文字)にします。
これは関数 C<lcfirst> および C<ucfirst> と似たような機能を提供します。
=begin original
To uppercase or lowercase several characters, one might want to use
C<\L> or C<\U>, which will lowercase/uppercase all characters following
them, until either the end of the pattern or the next occurrence of
C<\E>, whichever comes first. They provide functionality similar to what
the functions C<lc> and C<uc> provide.
=end original
複数の文字を大文字または小文字にするのに、C<\L> または C<\U> を
使いたいかもしれません; これは、パターンの末尾または次に
C<\E> が現れるまでの全ての文字を小文字/大文字にします。
これらは関数 C<lc> および C<uc> と同じような機能を提供します。
=begin original
C<\Q> is used to quote (disable) pattern metacharacters, up to the next
C<\E> or the end of the pattern. C<\Q> adds a backslash to any character
that could have special meaning to Perl. In the ASCII range, it quotes
every character that isn't a letter, digit, or underscore. See
L<perlfunc/quotemeta> for details on what gets quoted for non-ASCII
code points. Using this ensures that any character between C<\Q> and
C<\E> will be matched literally, not interpreted as a metacharacter by
the regex engine.
=end original
C<\Q> は引き続く文字列を、次の C<\E> またはパターンの最後まで
クォート(無効化)します。
C<\Q> は Perl で特殊な意味を持つ全ての文字に逆スラッシュを追加します。
ASCII の範囲では、英字、数字、下線でないものをクォートします。
非 ASCII 符号位置で何がクォートされるかに関する詳細については
L<perlfunc/quotemeta> を参照してください。
これにより C<\Q> と C<\E> の間の全ての文字はリテラルにマッチングし、
正規表現エンジンによってメタ文字として解釈されません。
=begin original
C<\F> can be used to casefold all characters following, up to the next C<\E>
or the end of the pattern. It provides the functionality similar to
the C<fc> function.
=end original
C<\F> は次の C<\E> またはパターンの最後まで畳み込み文字にします。
これは C<fc> 関数と似たような機能を提供します。
=begin original
Mnemonic: I<L>owercase, I<U>ppercase, I<F>old-case, I<Q>uotemeta, I<E>nd.
=end original
記憶法: 小文字(I<L>owercase)、大文字(I<U>ppercase)、畳み込み文字
(I<F>old-case)、クォート(I<Q>uotemeta)、終了(I<E>nd)。
=head4 Examples
(例)
$sid = "sid";
$greg = "GrEg";
$miranda = "(Miranda)";
$str =~ /\u$sid/; # Matches 'Sid'
$str =~ /\L$greg/; # Matches 'greg'
$str =~ /\Q$miranda\E/; # Matches '(Miranda)', as if the pattern
# had been written as /\(Miranda\)/
=head2 Character classes
(文字クラス)
=begin original
Perl regular expressions have a large range of character classes. Some of
the character classes are written as a backslash sequence. We will briefly
discuss those here; full details of character classes can be found in
L<perlrecharclass>.
=end original
Perl の正規表現は広い範囲の文字クラスを持っています。
文字クラスの一部は逆スラッシュシーケンスとして書かれます。
ここではそれらについて簡潔に議論します; 文字クラスに関する完全な詳細は
L<perlrecharclass> にあります。
=begin original
C<\w> is a character class that matches any single I<word> character
(letters, digits, Unicode marks, and connector punctuation (like the
underscore)). C<\d> is a character class that matches any decimal
digit, while the character class C<\s> matches any whitespace character.
New in perl 5.10.0 are the classes C<\h> and C<\v> which match horizontal
and vertical whitespace characters.
=end original
C<\w> は単一の任意の I<単語> 文字 (英字、数字、Unicode マーク、
(下線のような)接続句読点) にマッチングする文字クラスです。
C<\d> は 10 進数字にマッチングする文字クラスです; 一方文字クラス C<\s> は
空白文字にマッチングします。
perl 5.10.0 から導入されたのは、それぞれ水平空白文字と垂直空白文字に
マッチングする C<\h> と C<\v> です。
=begin original
The exact set of characters matched by C<\d>, C<\s>, and C<\w> varies
depending on various pragma and regular expression modifiers. It is
possible to restrict the match to the ASCII range by using the C</a>
regular expression modifier. See L<perlrecharclass>.
=end original
C<\d>, C<\s>, C<\w> でマッチングする文字の正確な集合は様々なプラグマと
正規表現修飾子に依存して異なります。
C</a> 正規表現修飾子を使うことで ASCII の範囲にマッチングするように
制限できます。
L<perlrecharclass> を参照してください。
=begin original
The uppercase variants (C<\W>, C<\D>, C<\S>, C<\H>, and C<\V>) are
character classes that match, respectively, any character that isn't a
word character, digit, whitespace, horizontal whitespace, or vertical
whitespace.
=end original
大文字の変種 (C<\W>, C<\D>, C<\S>, C<\H>, C<\V>) はそれぞれ単語文字、数字、
空白、水平空白、垂直空白ではない任意の文字にマッチングします。
=begin original
Mnemonics: I<w>ord, I<d>igit, I<s>pace, I<h>orizontal, I<v>ertical.
=end original
記憶法: 単語(I<w>ord)、数字(I<d>igit)、空白(I<s>pace)、水平(I<h>orizontal)、
垂直(I<v>ertical)。
=head3 Unicode classes
(Unicode クラス)
=begin original
C<\pP> (where C<P> is a single letter) and C<\p{Property}> are used to
match a character that matches the given Unicode property; properties
include things like "letter", or "thai character". Capitalizing the
sequence to C<\PP> and C<\P{Property}> make the sequence match a character
that doesn't match the given Unicode property. For more details, see
L<perlrecharclass/Backslash sequences> and
L<perlunicode/Unicode Character Properties>.
=end original
C<\pP> (ここで C<P> は単一の文字) と C<\p{Property}> は与えられた Unicode
特性にマッチングする文字にマッチングしていました; 特性には "letter" や
"thai character" のようなものが含まれます。
並びを C<\PP> と C<\P{Property}> のようにキャピタライズすると、与えられた
Unicode 特性にマッチングしない文字にマッチングするようになります。
さらなる詳細については、L<perlrecharclass/Backslash sequences> と
L<perlunicode/Unicode Character Properties> を参照してください。
=begin original
Mnemonic: I<p>roperty.
=end original
記憶法: 特性(I<p>roperty)。
=head2 Referencing
(参照)
=begin original
If capturing parenthesis are used in a regular expression, we can refer
to the part of the source string that was matched, and match exactly the
same thing. There are three ways of referring to such I<backreference>:
absolutely, relatively, and by name.
=end original
正規表現で捕捉かっこが使われると、マッチングしたソース文字列の一部を
参照したり、全く同じものにマッチングしたりできます。
このような I<後方参照> を参照するには三つの方法があります: 絶対、相対、
名前付きです。
=for later add link to perlrecapture
=head3 Absolute referencing
(絶対参照)
=begin original
Either C<\gI<N>> (starting in Perl 5.10.0), or C<\I<N>> (old-style) where I<N>
is a positive (unsigned) decimal number of any length is an absolute reference
to a capturing group.
=end original
(Perl 5.10.0 に導入された) C<\gI<N>> または (古い形式の) C<\I<N>> で I<N> が
任意の長さの正の(符号なし)10 進数の場合、捕捉グループへの絶対参照です。
=begin original