/
perlrecharclass.pod
2058 lines (1466 loc) · 65.8 KB
/
perlrecharclass.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
X<character class>
=begin original
perlrecharclass - Perl Regular Expression Character Classes
=end original
perlrecharclass - 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 manual page discusses the syntax and use of character
classes in Perl regular expressions.
=end original
このマニュアルページは Perl 正規表現の文字クラスの文法と使用法について
議論します。
=begin original
A character class is a way of denoting a set of characters
in such a way that one character of the set is matched.
It's important to remember that: matching a character class
consumes exactly one character in the source string. (The source
string is the string the regular expression is matched against.)
=end original
文字クラスは、集合の中の一文字がマッチングするというような方法で、
文字の集合を指定するための方法です。
次のことを覚えておくことは重要です: 文字集合はソース文字列の中から正確に
一文字だけを消費します。
(ソース文字列とは正規表現がマッチングしようとしている文字列です。)
=begin original
There are three types of character classes in Perl regular
expressions: the dot, backslash sequences, and the form enclosed in square
brackets. Keep in mind, though, that often the term "character class" is used
to mean just the bracketed form. Certainly, most Perl documentation does that.
=end original
Perl 正規表現には 3 種類の文字クラスがあります: ドット、
逆スラッシュシーケンス、大かっこで囲まれた形式です。
しかし、「文字クラス」という用語はしばしば大かっこ形式だけを意味するために
使われることに注意してください。
確かに、ほとんどの Perl 文書ではそうなっています。
=head2 The dot
(ドット)
=begin original
The dot (or period), C<.> is probably the most used, and certainly
the most well-known character class. By default, a dot matches any
character, except for the newline. That default can be changed to
add matching the newline by using the I<single line> modifier: either
for the entire regular expression with the C</s> modifier, or
locally with C<(?s)>. (The experimental C<\N> backslash sequence, described
below, matches any character except newline without regard to the
I<single line> modifier.)
=end original
ドット (またはピリオド) C<.> はおそらくもっともよく使われ、そして確実に
もっともよく知られている文字クラスです。
デフォルトでは、ドットは改行を除く任意の文字にマッチングします。
このデフォルトは I<単一行> 修飾子を使うことで改行にもマッチングするように
変更されます: 正規表現全体に対して C</s> 修飾子を使うか、ローカルには
C<(?s)> を使います。
(後述する実験的な C<\N> 逆スラッシュシーケンスでは、I<単一行> 修飾子に
関わりなく改行以外の任意の文字にマッチングします。)
=begin original
Here are some examples:
=end original
以下は例です:
=begin original
"a" =~ /./ # Match
"." =~ /./ # Match
"" =~ /./ # No match (dot has to match a character)
"\n" =~ /./ # No match (dot does not match a newline)
"\n" =~ /./s # Match (global 'single line' modifier)
"\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
"ab" =~ /^.$/ # No match (dot matches one character)
=end original
"a" =~ /./ # マッチングする
"." =~ /./ # マッチングする
"" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
"\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
"\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
"\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
"ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
=head2 Backslash sequences
X<\w> X<\W> X<\s> X<\S> X<\d> X<\D> X<\p> X<\P>
X<\N> X<\v> X<\V> X<\h> X<\H>
X<word> X<whitespace>
(逆スラッシュシーケンス)
=begin original
A backslash sequence is a sequence of characters, the first one of which is a
backslash. Perl ascribes special meaning to many such sequences, and some of
these are character classes. That is, they match a single character each,
provided that the character belongs to the specific set of characters defined
by the sequence.
=end original
逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。
Perl はそのような並びの多くに特別な意味を持たせていて、
その一部は文字クラスです。
つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に
帰属する一文字にマッチングします。
=begin original
Here's a list of the backslash sequences that are character classes. They
are discussed in more detail below. (For the backslash sequences that aren't
character classes, see L<perlrebackslash>.)
=end original
以下は文字クラスの逆スラッシュシーケンスの一覧です。
以下でさらに詳細に議論します。
(文字クラスではない逆スラッシュシーケンスについては、L<perlrebackslash> を
参照してください。)
=begin original
\d Match a decimal digit character.
\D Match a non-decimal-digit character.
\w Match a "word" character.
\W Match a non-"word" character.
\s Match a whitespace character.
\S Match a non-whitespace character.
\h Match a horizontal whitespace character.
\H Match a character that isn't horizontal whitespace.
\v Match a vertical whitespace character.
\V Match a character that isn't vertical whitespace.
\N Match a character that isn't a newline. Experimental.
\pP, \p{Prop} Match a character that has the given Unicode property.
\PP, \P{Prop} Match a character that doesn't have the Unicode property
=end original
\d 10 進数字にマッチング。
\D 非 10 進数字にマッチング。
\w 「単語」文字にマッチング。
\W 非「単語」文字にマッチング。
\s 空白文字にマッチング。
\S 非空白文字にマッチング。
\h 水平空白文字にマッチング。
\H 水平空白でない文字にマッチング。
\v 垂直空白文字にマッチング。
\V 垂直空白でない文字にマッチング。
\N 改行以外の文字にマッチング。実験的。
\pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
\PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
=head3 \N
=begin original
C<\N> is new in 5.12, and is experimental. It, like the dot, matches any
character that is not a newline. The difference is that C<\N> is not influenced
by the I<single line> regular expression modifier (see L</The dot> above). Note
that the form C<\N{...}> may mean something completely different. When the
C<{...}> is a L<quantifier|perlre/Quantifiers>, it means to match a non-newline
character that many times. For example, C<\N{3}> means to match 3
non-newlines; C<\N{5,}> means to match 5 or more non-newlines. But if C<{...}>
is not a legal quantifier, it is presumed to be a named character. See
L<charnames> for those. For example, none of C<\N{COLON}>, C<\N{4F}>, and
C<\N{F4}> contain legal quantifiers, so Perl will try to find characters whose
names are respectively C<COLON>, C<4F>, and C<F4>.
=end original
C<\N> は 5.12 の新機能で、実験的なものです。
これは、ドットのように、改行以外の任意の文字にマッチングします。
違いは、C<\N> は I<単一行> 正規表現修飾子の影響を受けないことです
(上述の L</The dot> 参照)。
C<\N{...}> 型式は何か全く違うものを意味するかも知れないことに
注意してください。
C<{...}> が L<量指定子|perlre/Quantifiers> なら、これは指定された回数の
非改行文字にマッチングします。
例えば、C<\N{3}> は三つの非改行にマッチングします;
C<\N{5,}> は五つ以上の非改行にマッチングします。
しかし、C<{...}> が有効な量指定子でない場合、これは名前付き文字と
推定されます。
これについては L<charnames> を参照してください。
例えば、C<\N{COLON}>, C<\N{4F}>, C<\N{F4}> はどれも有効な
量指定子ではないので、Perl はそれぞれ C<COLON>, C<4F>, C<F4> という名前の
文字を探そうとします。
=head3 Digits
(数字)
=begin original
C<\d> matches a single character considered to be a decimal I<digit>.
If the C</a> regular expression modifier is in effect, it matches [0-9].
Otherwise, it
matches anything that is matched by C<\p{Digit}>, which includes [0-9].
(An unlikely possible exception is that under locale matching rules, the
current locale might not have [0-9] matched by C<\d>, and/or might match
other characters whose code point is less than 256. Such a locale
definition would be in violation of the C language standard, but Perl
doesn't currently assume anything in regard to this.)
=end original
C<\d> は 10 進 I<数字> と考えられる単一の文字にマッチングします。
C</a> 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。
さもなければ、これは [0-9] を含む、C<\p{Digit}> にマッチングするものに
マッチングします。
(ありそうもない例外はロケールマッチングの下で、現在のロケールが
C<\d> にマッチングする [0-9] がないか、
符号位置が 256 未満の他の文字にマッチングすることです。
このようなロケール定義は C 言語標準に違反していますが、
Perl は今のところこれに関して何も仮定しません。)
=begin original
What this means is that unless the C</a> modifier is in effect C<\d> not
only matches the digits '0' - '9', but also Arabic, Devanagari, and
digits from other languages. This may cause some confusion, and some
security issues.
=end original
これが意味することは、C</a> 修飾子が有効でない限り、C<\d> は数字
'0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の
数字もマッチングします。
これは混乱やセキュリティ問題を引き起こすことがあります。
=begin original
Some digits that C<\d> matches look like some of the [0-9] ones, but
have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks
very much like an ASCII DIGIT EIGHT (U+0038). An application that
is expecting only the ASCII digits might be misled, or if the match is
C<\d+>, the matched string might contain a mixture of digits from
different writing systems that look like they signify a number different
than they actually do. L<Unicode::UCD/num()> can
be used to safely
calculate the value, returning C<undef> if the input string contains
such a mixture.
=end original
C<\d> にマッチングする数字には、[0-9] のように見えるけれども、
異なる値を持つものもあります。
例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038) と
とてもよく似ています。
ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、
マッチングが C<\d+> の場合、
マッチングした文字列は、実際と異なる値を示しているように見える、
異なった書記体系からの数字が混ざったものかもしれません。
L<Unicode::UCD/num()> は値を安全に計算するのに使えます;
入力文字列がこのような混合を含んでいる場合は C<undef> を返します。
=begin original
What C<\p{Digit}> means (and hence C<\d> except under the C</a>
modifier) is C<\p{General_Category=Decimal_Number}>, or synonymously,
C<\p{General_Category=Digit}>. Starting with Unicode version 4.1, this
is the same set of characters matched by C<\p{Numeric_Type=Decimal}>.
But Unicode also has a different property with a similar name,
C<\p{Numeric_Type=Digit}>, which matches a completely different set of
characters. These characters are things such as C<CIRCLED DIGIT ONE>
or subscripts, or are from writing systems that lack all ten digits.
=end original
C<\p{Digit}> が意味するもの(つまり、C</a> 修飾子の下でない C<\d>)は、
C<\p{General_Category=Decimal_Number}>、または同義語として
C<\p{General_Category=Digit}> です。
Unicode バージョン 4.1 以降では、これは C<\p{Numeric_Type=Decimal}> に
マッチングする文字集合と同じです。
ただし、Unicode には、C<\p{Numeric_Type=Digit}> という類似した名前を持つ
別の特性もあります; これは完全に異なる文字集合とマッチングします。
これらの文字は、C<CIRCLEED DIGIT ONE> や添字のようなものであるか、
10 の数字すべてが揃っていない書記体系からのものです。
=begin original
The design intent is for C<\d> to exactly match the set of characters
that can safely be used with "normal" big-endian positional decimal
syntax, where, for example 123 means one 'hundred', plus two 'tens',
plus three 'ones'. This positional notation does not necessarily apply
to characters that match the other type of "digit",
C<\p{Numeric_Type=Digit}>, and so C<\d> doesn't match them.
=end original
設計意図は、C<\d> が「通常の」ビッグエンディアンの
位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を
加えたものを意味する) で安全に使用できる文字集合と
正確にマッチングするようにすることです;
この位置表記は、他のタイプの「digit」である C<\p{Numeric_Type=Digit}> に
マッチングする文字には必ずしも適用されないため、
C<\d> はこれらの文字にマッチングしません。
=begin original
The Tamil digits (U+0BE6 - U+0BEF) can also legally be
used in old-style Tamil numbers in which they would appear no more than
one in a row, separated by characters that mean "times 10", "times 100",
etc. (See L<http://www.unicode.org/notes/tn21>.)
=end original
タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の
数字でも合法的に使用することができます;
この数字は、「×10」や「×100」などを意味する文字で区切られて、
1 回に一度にしか現れません。
(L<http://www.unicode.org/notes/tn21>を参照してください)。
=begin original
Any character not matched by C<\d> is matched by C<\D>.
=end original
C<\d> にマッチングしない任意の文字は C<\D> にマッチングします。
=head3 Word characters
(単語文字)
=begin original
A C<\w> matches a single alphanumeric character (an alphabetic character, or a
decimal digit) or a connecting punctuation character, such as an
underscore ("_"). It does not match a whole word. To match a whole
word, use C<\w+>. This isn't the same thing as matching an English word, but
in the ASCII range it is the same as a string of Perl-identifier
characters.
=end original
C<\w> は単語全体ではなく、単一の英数字(つまり英字または数字)または
下線(C<_>) のような接続句読点にマッチングします。
これは単語全体にはマッチングしません。
単語全体にマッチングするには、C<\w+> を使ってください。
これは英語の単語にマッチングするのと同じことではありませんが、
ASCII の範囲では、Perl の識別子文字の文字列と同じです。
=over
=item If the C</a> modifier is in effect ...
(C</a> 修飾子が有効なら ...)
=begin original
C<\w> matches the 63 characters [a-zA-Z0-9_].
=end original
C<\w> は 63 文字 [a-zA-Z0-9_] にマッチングします。
=item otherwise ...
(さもなければ ...)
=over
=item For code points above 255 ...
(256 以上の符号位置では ...)
=begin original
C<\w> matches the same as C<\p{Word}> matches in this range. That is,
it matches Thai letters, Greek letters, etc. This includes connector
punctuation (like the underscore) which connect two words together, or
diacritics, such as a C<COMBINING TILDE> and the modifier letters, which
are generally used to add auxiliary markings to letters.
=end original
C<\w> はこの範囲で C<\p{Word}> がマッチングするものと同じものに
マッチングします。
つまり、タイ文字、ギリシャ文字などです。
これには(下線のような)二つの単語を繋ぐ接続句読点、
C<COMBINING TILDE> や一般的に文字に追加のマークを付けるために
使われる修飾字のようなダイアクリティカルマークが含まれます。
=item For code points below 256 ...
(255 以下の符号位置では ...)
=over
=item if locale rules are in effect ...
(ロケール規則が有効なら ...)
=begin original
C<\w> matches the platform's native underscore character plus whatever
the locale considers to be alphanumeric.
=end original
C<\w> は、プラットフォームのネイティブな下線に加えてロケールが英数字と
考えるものにマッチングします。
=item if Unicode rules are in effect or if on an EBCDIC platform ...
(Unicode 規則が有効か、EBCDIC プラットフォームなら ...)
=begin original
C<\w> matches exactly what C<\p{Word}> matches.
=end original
C<\w> は C<\p{Word}> がマッチングするものと同じものにマッチングします。
=item otherwise ...
(さもなければ ...)
=begin original
C<\w> matches [a-zA-Z0-9_].
=end original
C<\w> は [a-zA-Z0-9_] にマッチングします。
=back
=back
=back
=begin original
Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
=end original
どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
記述されている方法で決定されます。
=begin original
There are a number of security issues with the full Unicode list of word
characters. See L<http://unicode.org/reports/tr36>.
=end original
完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。
L<http://unicode.org/reports/tr36> を参照してください。
=begin original
Also, for a somewhat finer-grained set of characters that are in programming
language identifiers beyond the ASCII range, you may wish to instead use the
more customized L</Unicode Properties>, C<\p{ID_Start}>,
C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}>. See
L<http://unicode.org/reports/tr31>.
=end original
また、ASCII の範囲を超えたプログラミング言語識別子のための
より高精度の文字集合のためには、代わりによりカスタマイズされた
L<Unicode 特性|/Unicode Properties>である
C<\p{ID_Start}>,
C<\p{ID_Continue}>, C<\p{XID_Start}>, and C<\p{XID_Continue}> を
使った方がよいでしょう。
L<http://unicode.org/reports/tr31> を参照してください。
=begin original
Any character not matched by C<\w> is matched by C<\W>.
=end original
C<\w> にマッチングしない任意の文字は C<\W> にマッチングします。
=head3 Whitespace
(空白)
=begin original
C<\s> matches any single character considered whitespace.
=end original
C<\s> は空白と考えられる単一の文字にマッチングします。
=over
=item If the C</a> modifier is in effect ...
(C</a> 修飾子が有効なら ...)
=begin original
C<\s> matches the 5 characters [\t\n\f\r ]; that is, the horizontal tab,
the newline, the form feed, the carriage return, and the space. (Note
that it doesn't match the vertical tab, C<\cK> on ASCII platforms.)
=end original
C<\s> は [\t\n\f\r ] の 5 文字にマッチングします; つまり、水平タブ、
改行、改頁、復帰、スペースです。
(ASCII プラットフォームでは C<\cK> である垂直タブには
マッチングしないことに注意してください。)
=item otherwise ...
(さもなければ ...)
=over
=item For code points above 255 ...
(256 以上の符号位置では ...)
=begin original
C<\s> matches exactly the code points above 255 shown with an "s" column
in the table below.
=end original
C<\s> は、後述する表の "s" の列で示されている、
255 を超える符号位置に正確にマッチングします。
=item For code points below 256 ...
(255 以下の符号位置では ...)
=over
=item if locale rules are in effect ...
(ロケール規則が有効なら ...)
=begin original
C<\s> matches whatever the locale considers to be whitespace. Note that
this is likely to include the vertical space, unlike non-locale C<\s>
matching.
=end original
C<\s> はロケールが空白だと考えるものにマッチングします。
これは非ロケールの C<\s> と異なりおそらく垂直スペースを含むことに
注意してください。
=item if Unicode rules are in effect or if on an EBCDIC platform ...
=begin original
C<\s> matches exactly the characters shown with an "s" column in the
table below.
=end original
C<\s> は正確に以下の表で "s" の列にある文字にマッチングします。
=item otherwise ...
=begin original
C<\s> matches [\t\n\f\r ].
Note that this list doesn't include the non-breaking space.
=end original
C<\s> は [\t\n\f\r ] にマッチングします。
この一覧にはノーブレークスペースが含まれていないことに注意してください。
=back
=back
=back
=begin original
Which rules apply are determined as described in L<perlre/Which character set modifier is in effect?>.
=end original
どの規則を適用するかは L<perlre/Which character set modifier is in effect?> で
記述されている方法で決定されます。
=begin original
Any character not matched by C<\s> is matched by C<\S>.
=end original
C<\s> にマッチングしない任意の文字は C<\S> にマッチングします。
=begin original
C<\h> matches any character considered horizontal whitespace;
this includes the platform's space and tab characters and several others
listed in the table below. C<\H> matches any character
not considered horizontal whitespace. They use the platform's native
character set, and do not consider any locale that may otherwise be in
use.
=end original
C<\h> は水平空白と考えられる任意の文字にマッチングします; これは
プラットフォームのスペースとタブ文字および以下の表に上げられている
いくつかのその他の文字です。
C<\H> は水平空白と考えられない文字にマッチングします。
これらはプラットフォームのネイティブな文字集合を使い、
他の場所では有効なロケールを考慮しません。
=begin original
C<\v> matches any character considered vertical whitespace;
this includes the platform's carriage return and line feed characters (newline)
plus several other characters, all listed in the table below.
C<\V> matches any character not considered vertical whitespace.
They use the platform's native character set, and do not consider any
locale that may otherwise be in use.
=end original
C<\v> は垂直空白と考えられる任意の文字にマッチングします; これは
プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です;
全ては以下の表に挙げられています。
C<\V> は垂直空白と考えられない任意の文字にマッチングします。
これらはプラットフォームのネイティブな文字集合を使い、
他の場所では有効なロケールを考慮しません。
=begin original
C<\R> matches anything that can be considered a newline under Unicode
rules. It's not a character class, as it can match a multi-character
sequence. Therefore, it cannot be used inside a bracketed character
class; use C<\v> instead (vertical whitespace). It uses the platform's
native character set, and does not consider any locale that may
otherwise be in use.
Details are discussed in L<perlrebackslash>.
=end original
C<\R> は Unicode の規則で改行と考えられるものにマッチングします。
複数文字の並びにマッチングすることもあるので、これは
文字クラスではありません。
従って、大かっこ文字クラスの中では使えません; 代わりに C<\v> (垂直空白) を
使ってください。
これらはプラットフォームのネイティブな文字集合を使い、
他の場所では有効なロケールを考慮しません。
詳細は L<perlrebackslash> で議論しています。
=begin original
Note that unlike C<\s> (and C<\d> and C<\w>), C<\h> and C<\v> always match
the same characters, without regard to other factors, such as the active
locale or whether the source string is in UTF-8 format.
=end original
C<\s> (および C<\d> と C<\w>) と違って、C<\h> および C<\v> は、現在の
ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず
同じ文字にマッチングします。
=begin original
One might think that C<\s> is equivalent to C<[\h\v]>. This is not true.
The difference is that the vertical tab (C<"\x0b">) is not matched by
C<\s>; it is however considered vertical whitespace.
=end original
C<\s> が C<[\h\v]> と等価と考える人がいるかもしれません。
これは正しくありません。
違いは、垂直タブ (C<"\x0b">) は C<\s> にマッチングしないということです;
垂直空白と考えられます。
=begin original
The following table is a complete listing of characters matched by
C<\s>, C<\h> and C<\v> as of Unicode 6.0.
=end original
以下の表は Unicode 6.0 現在で C<\s>, C<\h>, C<\v> にマッチングする文字の
完全な一覧です。
=begin original
The first column gives the Unicode code point of the character (in hex format),
the second column gives the (Unicode) name. The third column indicates
by which class(es) the character is matched (assuming no locale or EBCDIC code
page is in effect that changes the C<\s> matching).
=end original
最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の)
名前です。
3 番目の列はどのクラスにマッチングするかを示しています
(C<\s> のマッチングを変更するようなロケールや EBCDIC コードページが
有効でないことを仮定しています)。
0x0009 CHARACTER TABULATION h s
0x000a LINE FEED (LF) vs
0x000b LINE TABULATION v
0x000c FORM FEED (FF) vs
0x000d CARRIAGE RETURN (CR) vs
0x0020 SPACE h s
0x0085 NEXT LINE (NEL) vs [1]
0x00a0 NO-BREAK SPACE h s [1]
0x1680 OGHAM SPACE MARK h s
0x180e MONGOLIAN VOWEL SEPARATOR h s
0x2000 EN QUAD h s
0x2001 EM QUAD h s
0x2002 EN SPACE h s
0x2003 EM SPACE h s
0x2004 THREE-PER-EM SPACE h s
0x2005 FOUR-PER-EM SPACE h s
0x2006 SIX-PER-EM SPACE h s
0x2007 FIGURE SPACE h s
0x2008 PUNCTUATION SPACE h s
0x2009 THIN SPACE h s
0x200a HAIR SPACE h s
0x2028 LINE SEPARATOR vs
0x2029 PARAGRAPH SEPARATOR vs
0x202f NARROW NO-BREAK SPACE h s
0x205f MEDIUM MATHEMATICAL SPACE h s
0x3000 IDEOGRAPHIC SPACE h s
=over 4
=item [1]
=begin original
NEXT LINE and NO-BREAK SPACE may or may not match C<\s> depending
on the rules in effect. See
L<the beginning of this section|/Whitespace>.
=end original
NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって C<\s> に
マッチングしたりマッチングしなかったりします。
L<the beginning of this section|/Whitespace> を参照してください。
=back
=head3 Unicode Properties
(Unicode 特性)
=begin original
C<\pP> and C<\p{Prop}> are character classes to match characters that fit given
Unicode properties. One letter property names can be used in the C<\pP> form,
with the property name following the C<\p>, otherwise, braces are required.
When using braces, there is a single form, which is just the property name
enclosed in the braces, and a compound form which looks like C<\p{name=value}>,
which means to match if the property "name" for the character has that particular
"value".
For instance, a match for a number can be written as C</\pN/> or as
C</\p{Number}/>, or as C</\p{Number=True}/>.
Lowercase letters are matched by the property I<Lowercase_Letter> which
has the short form I<Ll>. They need the braces, so are written as C</\p{Ll}/> or
C</\p{Lowercase_Letter}/>, or C</\p{General_Category=Lowercase_Letter}/>
(the underscores are optional).
C</\pLl/> is valid, but means something different.
It matches a two character string: a letter (Unicode property C<\pL>),
followed by a lowercase C<l>.
=end original
C<\pP> と C<\p{Prop}> は指定された Unicode 特性に一致する文字に
マッチングする文字クラスです。
一文字特性は C<\pP> 形式で、C<\p> に引き続いて特性名です; さもなければ
中かっこが必要です。
中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、
C<\p{name=value}> のような形で、文字の特性 "name" が特定の "value" を
持つものにマッチングすることになる複合形式があります。
例えば、数字にマッチングするものは C</\pN/> または C</\p{Number}/> または
C</\p{Number=True}/> と書けます。
小文字は I<LowercaseLetter> 特性にマッチングします; これには
I<Ll> と言う短縮形式があります。
中かっこが必要なので、C</\p{Ll}/> または C</\p{Lowercase_Letter}/> または
C</\p{General_Category=Lowercase_Letter}/> と書きます(下線はオプションです)。
C</\pLl/> も妥当ですが、違う意味になります。
これは 2 文字にマッチングします: 英字 (Unicode 特性 C<\pL>)に引き続いて
小文字の C<l> です。
=begin original
If neither the C</a> modifier nor locale rules are in effect, the use of
a Unicode property will force the regular expression into using Unicode
rules.
=end original
C</a> 修飾子もロケール規則も有効でない場合、Unicode 特性を使うと
正規表現に Unicode 規則を使うように強制します。
=begin original
Note that almost all properties are immune to case-insensitive matching.
That is, adding a C</i> regular expression modifier does not change what
they match. There are two sets that are affected. The first set is
C<Uppercase_Letter>,
C<Lowercase_Letter>,
and C<Titlecase_Letter>,
all of which match C<Cased_Letter> under C</i> matching.
The second set is
C<Uppercase>,
C<Lowercase>,
and C<Titlecase>,
all of which match C<Cased> under C</i> matching.
(The difference between these sets is that some things, such as Roman
numerals, come in both upper and lower case, so they are C<Cased>, but
aren't considered to be letters, so they aren't C<Cased_Letter>s. They're
actually C<Letter_Number>s.)
This set also includes its subsets C<PosixUpper> and C<PosixLower>, both
of which under C</i> match C<PosixAlpha>.
=end original
ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに
注意してください。
つまり、C</i> 正規表現修飾子はこれらがマッチングするものに影響を
与えないということです。
影響を与える二つの集合があります。
一つ目の集合は
C<Uppercase_Letter>,
C<Lowercase_Letter>,
C<Titlecase_Letter> で、全て C</i> マッチングの下で
C<Cased_Letter> にマッチングします。
二つ目の集合は
C<Uppercase>,
C<Lowercase>,
C<Titlecase> で、全てC</i> マッチングの下で
C<Cased> にマッチングします。
(これらの集合の違いは、ローマ数字のような一部のものは、
大文字と小文字があるので C<Cased> ですが、
文字とは扱われないので C<Cased_Letter> ではありません。
これらは実際には C<Letter_Number> です。)
この集合はその部分集合である C<PosixUpper> と C<PosixLower> を含みます;
これら両方は C</i> マッチングの下では C<PosixAlpha> にマッチングします。
=begin original
For more details on Unicode properties, see L<perlunicode/Unicode
Character Properties>; for a
complete list of possible properties, see
L<perluniprops/Properties accessible through \p{} and \P{}>,
which notes all forms that have C</i> differences.
It is also possible to define your own properties. This is discussed in
L<perlunicode/User-Defined Character Properties>.
=end original
Unicode 特性に関するさらなる詳細については、
L<perlunicode/Unicode Character Properties> を参照してください; 特性の完全な
一覧については、C</i> に違いのある全ての形式について記されている
L<perluniprops/Properties accessible through \p{} and \P{}> を参照して
ください。
独自の特性を定義することも可能です。
これは L<perlunicode/User-Defined Character Properties> で
議論されています。
=begin original
Unicode properties are defined (surprise!) only on Unicode code points.
A warning is raised and all matches fail on non-Unicode code points
(those above the legal Unicode maximum of 0x10FFFF). This can be
somewhat surprising,
=end original
Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ
定義されています。
非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) への
マッチングの失敗は警告が発生します。
これは驚かされるものかもしれません。
chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails.
chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails!
=begin original
Even though these two matches might be thought of as complements, they
are so only on Unicode code points.
=end original
これら二つのマッチングは補集合と考えるかもしれませんが、
これらは Unicode 符号位置だけです。
=head4 Examples
(例)
=begin original
"a" =~ /\w/ # Match, "a" is a 'word' character.
"7" =~ /\w/ # Match, "7" is a 'word' character as well.
"a" =~ /\d/ # No match, "a" isn't a digit.
"7" =~ /\d/ # Match, "7" is a digit.
" " =~ /\s/ # Match, a space is whitespace.
"a" =~ /\D/ # Match, "a" is a non-digit.
"7" =~ /\D/ # No match, "7" is not a non-digit.
" " =~ /\S/ # No match, a space is not non-whitespace.
=end original
"a" =~ /\w/ # マッチング; "a" は「単語」文字。
"7" =~ /\w/ # マッチング; "7" も「単語」文字。
"a" =~ /\d/ # マッチングしない; "a" は数字ではない。
"7" =~ /\d/ # マッチング; "7" は数字。
" " =~ /\s/ # マッチング; スペースは空白。
"a" =~ /\D/ # マッチング; "a" は非数字。
"7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
" " =~ /\S/ # マッチングしない; スペースは非空白ではない。
=begin original
" " =~ /\h/ # Match, space is horizontal whitespace.
" " =~ /\v/ # No match, space is not vertical whitespace.
"\r" =~ /\v/ # Match, a return is vertical whitespace.
=end original
" " =~ /\h/ # マッチング; スペースは水平空白。
" " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
"\r" =~ /\v/ # マッチング; 復帰は垂直空白。
=begin original
"a" =~ /\pL/ # Match, "a" is a letter.
"a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.
=end original
"a" =~ /\pL/ # マッチング; "a" は英字。
"a" =~ /\p{Lu}/ # マッチングしない; /\p{Lu}/ は大文字にマッチングする。
=begin original
"\x{0e0b}" =~ /\p{Thai}/ # Match, \x{0e0b} is the character
# 'THAI CHARACTER SO SO', and that's in
# Thai Unicode class.
"a" =~ /\P{Lao}/ # Match, as "a" is not a Laotian character.
=end original
"\x{0e0b}" =~ /\p{Thai}/ # マッチング; \x{0e0b} は文字
# 'THAI CHARACTER SO SO' で、これは
# Thai Unicode クラスにある。
"a" =~ /\P{Lao}/ # マッチング; "a" はラオス文字ではない。
=begin original
It is worth emphasizing that C<\d>, C<\w>, etc, match single characters, not
complete numbers or words. To match a number (that consists of digits),
use C<\d+>; to match a word, use C<\w+>. But be aware of the security
considerations in doing so, as mentioned above.