-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.texi
2053 lines (1842 loc) · 112 KB
/
search.texi
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
@c =============================================================
@c = 元 翻 訳: 高汐一紀@電気通信大学
@c = 加筆修正: 大木敦雄@大塚.筑波大学 = 1998/11/25
@c = 20.4改訂: 大木敦雄@大塚.筑波大学 = 1999/09/12
@c =============================================================
@c This is part of the Emacs manual.
@c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 2000, 2001
@c Free Software Foundation, Inc.
@c See file emacs.texi for copying conditions.
@node Search, Fixit, Display, Top
@c @chapter Searching and Replacement
@chapter 探索と置換 @emph{(2004/03/27)}
@c @cindex searching
@c @cindex finding strings within text
@cindex 探索
@cindex テキスト内での文字列探索
@c Like other editors, Emacs has commands for searching for occurrences of
@c a string. The principal search command is unusual in that it is
@c @dfn{incremental}; it begins to search before you have finished typing the
@c search string. There are also nonincremental search commands more like
@c those of other editors.
他のエディタと同様に、Emacsにも文字列を探索するコマンドがあります。
主な探索コマンドが@dfn{インクリメンタル}(incremental)であるという点で、
普通とは違います。
探索したい文字列全体を入力し終えなくても、探索を始めます。
他のエディタの探索コマンドのように、
インクリメンタルでない探索コマンドもあります。
@c Besides the usual @code{replace-string} command that finds all
@c occurrences of one string and replaces them with another, Emacs has a
@c more flexible replacement command called @code{query-replace}, which
@c asks interactively which occurrences to replace.
指定した文字列の出現すべてを探し出して別の文字列に置換する、
普通の置換コマンド@code{replace-string}に加えて、
Emacsにはより柔軟な、
出現箇所をみつけるたびに置換するかどうか対話的に尋ねる
問い合わせ型置換コマンド@code{query-replace}もあります。
@menu
* Incremental Search:: Search happens as you type the string.
* Nonincremental Search:: Specify entire string and then search.
* Word Search:: Search for sequence of words.
* Regexp Search:: Search for match for a regexp.
* Regexps:: Syntax of regular expressions.
* Search Case:: To ignore case while searching, or not.
* Configuring Scrolling:: Scrolling within incremental search.
* Replace:: Search, and replace some or all matches.
* Other Repeating Search:: Operating on all matches for some regexp.
@end menu
@node Incremental Search, Nonincremental Search, Search, Search
@c @section Incremental Search
@section インクリメンタルサーチ @emph{(2004/03/26)}
@c @cindex incremental search
@cindex インクリメンタルサーチ
@c An incremental search begins searching as soon as you type the first
@c character of the search string. As you type in the search string, Emacs
@c shows you where the string (as you have typed it so far) would be
@c found. When you have typed enough characters to identify the place you
@c want, you can stop. Depending on what you plan to do next, you may or
@c may not need to terminate the search explicitly with @key{RET}.
インクリメンタルサーチでは、
探索文字列の最初の文字を打つとただちに探索を開始します。
探索文字列を入力するたびに、
Emacsは(それまでに入力した)文字列がどこでみつかるか表示します。
目的の箇所を特定するのに十分なだけの文字を打ってしまえば、
そこで終りにできます。
つぎに何をするかにもよりますが、
@key{RET}で探索を陽に終了する必要がある場合もあります。
@c WideCommands
@table @kbd
@item C-s
@c Incremental search forward (@code{isearch-forward}).
前向きにインクリメンタルサーチする(@code{isearch-forward})。
@item C-r
@c Incremental search backward (@code{isearch-backward}).
後向きにインクリメンタルサーチする(@code{isearch-backward})。
@end table
@kindex C-s
@findex isearch-forward
@c @kbd{C-s} starts a forward incremental search. It reads characters
@c from the keyboard, and moves point past the next occurrence of those
@c characters. If you type @kbd{C-s} and then @kbd{F}, that puts the
@c cursor after the first @samp{F} (the first following the starting point, since
@c this is a forward search). Then if you type an @kbd{O}, you will see
@c the cursor move just after the first @samp{FO} (the @samp{F} in that
@c @samp{FO} may or may not be the first @samp{F}). After another
@c @kbd{O}, the cursor moves after the first @samp{FOO} after the place
@c where you started the search. At each step, the buffer text that
@c matches the search string is highlighted, if the terminal can do that;
@c the current search string is always displayed in the echo area.
@kbd{C-s}は順方向へのインクリメンタルサーチを始めます。
@kbd{C-s}はキーボードから文字を読み取り、
打った文字が最初に現れる位置までカーソルを移動します。
たとえば、@kbd{C-s}に続けて@kbd{F}を打つと、
カーソルは最初に現れる@samp{F}の直後に移動します(順方向への検索なので続く文字の開始点になります)。
さらに@kbd{O}を打つと、カーソルは最初に現れる@samp{FO}の直後に移動します
(@samp{FO} の @samp{F} は最初の@samp{F}かもしれないし,違うかもしれない)。
さらに@kbd{O}を打つと、探索を開始した場所以降で最初に現れる
@samp{FOO}の直後にカーソルが移動します。
各段階において、反転表示できる端末では、
探索文字列に一致するバッファ内のテキストを強調表示します。
また、各段階において、エコー領域には現在の探索文字列がいつも表示されます。
@c If you make a mistake in typing the search string, you can cancel
@c characters with @key{DEL}. Each @key{DEL} cancels the last character of
@c search string. This does not happen until Emacs is ready to read another
@c input character; first it must either find, or fail to find, the character
@c you want to erase. If you do not want to wait for this to happen, use
@c @kbd{C-g} as described below.
探索する文字列を打ちまちがえたときには、@key{DEL}で取り消せます。
@key{DEL}を1回押すごとに、探索文字列の最後の文字を取り消していきます。
ただし、Emacsがつぎの入力文字を受け付け可能になるまで、
この取り消し操作は実行できません。
つまり、取り消そうと思っている文字をみつけるか、
もしくはみつけられなかったことが確定する必要があります。
それまで待てないなら、以下に説明するように@kbd{C-g}を使ってください。
@c When you are satisfied with the place you have reached, you can type
@c @key{RET}, which stops searching, leaving the cursor where the search
@c brought it. Also, any command not specially meaningful in searches
@c stops the searching and is then executed. Thus, typing @kbd{C-a}
@c would exit the search and then move to the beginning of the line.
@c @key{RET} is necessary only if the next command you want to type is a
@c printing character, @key{DEL}, @key{RET}, or another character that is
@c special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s},
@c @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-s}, and some other
@c meta-characters).
目的の箇所まで移動できたら、@key{RET}を打ちます。
すると、探索を終了しカーソルはその箇所に留まります。
また、探索に関係ないコマンドを打っても、
探索を終了し、そのコマンドを実行します。
したがって、@kbd{C-a}と打てば、探索を終了し、カーソルを行頭に移動します。
@key{RET}が必要な場面は、
つぎに入力したいコマンドが、印字文字、@key{DEL}、@key{RET}、および、
探索で特別な意味を持つその他の各種コントロール文字
(@kbd{C-q}、@kbd{C-w}、@kbd{C-r}、@kbd{C-s}、
@kbd{C-y}、@kbd{M-y}、@kbd{M-r}、@kbd{M-s})やいくつかのメタ文字である場合だけです。
@c Sometimes you search for @samp{FOO} and find one, but not the one you
@c expected to find. There was a second @samp{FOO} that you forgot
@c about, before the one you were aiming for. In this event, type
@c another @kbd{C-s} to move to the next occurrence of the search string.
@c You can repeat this any number of times. If you overshoot, you can
@c cancel some @kbd{C-s} characters with @key{DEL}.
@samp{FOO}を探してそれがみつかった場合でも、
予期していた@samp{FOO}ではないこともあるでしょう。
最初の@samp{FOO}以降に、2つめの@samp{FOO}があることを
忘れていたような場合です。
このようなときには、さらに@kbd{C-s}を打てば、
探索文字列のつぎの出現箇所に移動できます。
この操作は何度でも繰り返せます。
行き過ぎてしまったときには、@key{DEL}で@kbd{C-s}の操作を取り消せます。
@c After you exit a search, you can search for the same string again by
@c typing just @kbd{C-s C-s}: the first @kbd{C-s} is the key that invokes
@c incremental search, and the second @kbd{C-s} means ``search again.''
探索を終了したあとでも、単に@kbd{C-s C-s}と打てば、
ふたたび同じ文字列を探索できます。
つまり、最初の@kbd{C-s}がインクリメンタルサーチを起動して、
つぎの@kbd{C-s}が『再探索』を意味します。
@c To reuse earlier search strings, use the @dfn{search ring}. The
@c commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a search
@c string to reuse. These commands leave the selected search ring element
@c in the minibuffer, where you can edit it. Type @kbd{C-s} or @kbd{C-r}
@c to terminate editing the string and search for it.
以前に探索した文字列を再利用するには、
@dfn{探索リング}(search ring)を使います。
コマンド@kbd{M-p}と@kbd{M-n}でリング内を移動して、
再利用する文字列を取り出します。
これらのコマンドは、探索リング内の選択した要素をミニバッファに置きますから、
編集することも可能です。
@kbd{C-s}や@kbd{C-r}を打てば、
文字列の編集を終了して探索を開始できます。
@c If your string is not found at all, the echo area says @samp{Failing
@c I-Search}. The cursor is after the place where Emacs found as much of your
@c string as it could. Thus, if you search for @samp{FOOT}, and there is no
@c @samp{FOOT}, you might see the cursor after the @samp{FOO} in @samp{FOOL}.
@c At this point there are several things you can do. If your string was
@c mistyped, you can rub some of it out and correct it. If you like the place
@c you have found, you can type @key{RET} or some other Emacs command to
@c remain there. Or you can type @kbd{C-g}, which
@c removes from the search string the characters that could not be found (the
@c @samp{T} in @samp{FOOT}), leaving those that were found (the @samp{FOO} in
@c @samp{FOOT}). A second @kbd{C-g} at that point cancels the search
@c entirely, returning point to where it was when the search started.
探している文字列がまったくみつからなかった場合には、
エコー領域に@samp{Failing I-Search}と表示されます。
カーソルは、指定した文字列に可能な限り一致する箇所の直後にあります。
たとえば、@samp{FOOT}を探索しようとしたのに@samp{FOOT}がなければ、
カーソルは@samp{FOOL}の@samp{FOO}の直後にあります。
この時点でできることはいくつかあります。
文字列を打ちまちがえたのならば、それを消去して訂正します。
その箇所でよいのなら、その場所に留まるために、
@key{RET}か他のEmacsコマンドを打ちます。
あるいは、@kbd{C-g}を打てば、
探索文字列からみつけられなかった文字(@samp{FOOT}中の@samp{T})を取り除き、
みつけた文字列(@samp{FOOT}中の@samp{FOO})は
そのままにしておくこともできます。
ここで、さらに@kbd{C-g}を打つと、
探索全体を取り止めて、探索を開始した位置に戻ります。
@c An upper-case letter in the search string makes the search
@c case-sensitive. If you delete the upper-case character from the search
@c string, it ceases to have this effect. @xref{Search Case}.
探索文字列に大文字を指定すると、
大文字小文字を区別(case-sensitive)して探索します。
探索文字列から大文字を削除すると、この効果は消えます。
@xref{Search Case}。
@c To search for a newline, type @kbd{C-j}. To search for another
@c control character, such as control-S or carriage return, you must quote
@c it by typing @kbd{C-q} first. This function of @kbd{C-q} is analogous
@c to its use for insertion (@pxref{Inserting Text}): it causes the
@c following character to be treated the way any ``ordinary'' character is
@c treated in the same context. You can also specify a character by its
@c octal code: enter @kbd{C-q} followed by a sequence of octal digits.
改行を探索するには、@kbd{C-j}を打ちます。
コントロールSや改行などのコントロール文字を探索するには、
まず@kbd{C-q}を打ってクォートする必要があります。
@kbd{C-q}のこの機能は、挿入時の利用法に似ています
(@pxref{Inserting Text})。
このコマンドは、あとに続く文字を、
同じ文脈における『普通の』文字と同様に扱うようにします。
文字を8進コードで指定することもできて、
@kbd{C-q}に続けて8進数字列を入力します。
@cindex searching for non-@acronym{ASCII} characters
@cindex input method, during incremental search
@c To search for non-@acronym{ASCII} characters, you must use an input method
@c (@pxref{Input Methods}). If an input method is enabled in the
@c current buffer when you start the search, you can use it while you
@c type the search string also. Emacs indicates that by including the
@c input method mnemonic in its prompt, like this:
非@acronym{ASCII}文字を探索するためには,入力メソッド (@pxref{Input Methods}) を
使わなければなりません.探索を始める時に入力メソッドがオンになっていると,探索す
る時にも入力メソッドを利用できます.この時Emacs はプロンプトに以下のように入力メ
ソッドの略称を表示します.
@example
I-search [@var{im}]:
@end example
@noindent
@findex isearch-toggle-input-method
@findex isearch-toggle-specified-input-method
@c where @var{im} is the mnemonic of the active input method. You can
@c toggle (enable or disable) the input method while you type the search
@c string with @kbd{C-\} (@code{isearch-toggle-input-method}). You can
@c turn on a certain (non-default) input method with @kbd{C-^}
@c (@code{isearch-toggle-specified-input-method}), which prompts for the
@c name of the input method. The input method you enable during
@c incremental search remains enabled in the current buffer afterwards.
@var{im}は入力メソッドの略称です.検索中に @kbd{C-\}
(@code{isearch-toggle-input-method}) を入力することで,入力メソッドをトグル(有効
か無効かを切り替え)できます.@kbd{C-^}
(@code{isearch-toggle-specified-input-method}) である(デフォルトでない)入力メソッ
ドを有効にし,プロンプトに入力メソッド名を表示します.検索中に有効にした入力メソッ
ドは検索を終了しカレントバッファに戻っても有効な状態のまま保たれます.
@c If a search is failing and you ask to repeat it by typing another
@c @kbd{C-s}, it starts again from the beginning of the buffer.
@c Repeating a failing reverse search with @kbd{C-r} starts again from
@c the end. This is called @dfn{wrapping around}, and @samp{Wrapped}
@c appears in the search prompt once this has happened. If you keep on
@c going past the original starting point of the search, it changes to
@c @samp{Overwrapped}, which means that you are revisiting matches that
@c you have already seen.
探索に失敗したときに、さらに@kbd{C-s}を打って探索の続行を指示すると、
バッファの先頭からもう一度探索し始めます。
後向きの探索に失敗したときに再度@kbd{C-r}を打つと、
バッファの末尾から探索を再開します。
これらの操作は@dfn{巻き直し}(wrapping around)と呼ばれます。
巻き直しが起こると、探索のプロンプトには@samp{Wrapped}が表示されます。
もともとの探索開始位置を通過してなお探索を続けると、
表示が@samp{Overwrapped}に変わります。
これは、探索文字列にすでに一度一致した箇所を
再度探索していることを意味します。
@c @cindex quitting (in search)
@cindex 中断(探索)
@c The @kbd{C-g} ``quit'' character does special things during searches;
@c just what it does depends on the status of the search. If the search has
@c found what you specified and is waiting for input, @kbd{C-g} cancels the
@c entire search. The cursor moves back to where you started the search. If
@c @kbd{C-g} is typed when there are characters in the search string that have
@c not been found---because Emacs is still searching for them, or because it
@c has failed to find them---then the search string characters which have not
@c been found are discarded from the search string. With them gone, the
@c search is now successful and waiting for more input, so a second @kbd{C-g}
@c will cancel the entire search.
『中断』文字@kbd{C-g}は、探索中には特別な意味があり、
その機能は探索の状態に依存します。
指定したものがみつかり入力待ちの状態にあると、
@kbd{C-g}は探索全体を取り消します。
カーソルは探索開始位置に戻ります。
Emacsが探索中であったり探索に失敗したために、
探索文字列内に未発見の文字がある場合に@kbd{C-g}を打つと、
探索文字列から未発見の文字を消去します。
そうすると、これで探索が成功したことになるので、
入力待ちになります。
続けて@kbd{C-g}を打つと、探索全体を取り消します。
@c To search for a newline, type @kbd{C-j}. To search for another
@c control character, such as control-S or carriage return, you must quote
@c it by typing @kbd{C-q} first. This function of @kbd{C-q} is analogous
@c to its use for insertion (@pxref{Inserting Text}): it causes the
@c following character to be treated the way any ``ordinary'' character is
@c treated in the same context. You can also specify a character by its
@c octal code: enter @kbd{C-q} followed by a sequence of octal digits.
改行を探索するには、@kbd{C-j}を打ちます。
コントロールSや改行などのコントロール文字を探索するには、
まず@kbd{C-q}を打ってクォートする必要があります。
@kbd{C-q}のこの機能は、挿入時の利用法に似ています
(@pxref{Inserting Text})。
このコマンドは、あとに続く文字を、
同じ文脈における『普通の』文字と同様に扱うようにします。
文字を8進コードで指定することもできて、
@kbd{C-q}に続けて8進数字列を入力します。
@c You can change to searching backwards with @kbd{C-r}. If a search fails
@c because the place you started was too late in the file, you should do this.
@c Repeated @kbd{C-r} keeps looking for more occurrences backwards. A
@c @kbd{C-s} starts going forwards again. @kbd{C-r} in a search can be canceled
@c with @key{DEL}.
@kbd{C-r}を使えば、後向き探索に変更できます。
ファイルのうしろのほうで探索し始めたために探索に失敗したのであれば、
これを試してください。
@kbd{C-r}を繰り返し打つと、後向きにさらに探索を続けます。
@kbd{C-s}は、ふたたび前向き探索を再開します。
探索中の@kbd{C-r}は@key{DEL}で取り消せます。
@kindex C-r
@findex isearch-backward
@c If you know initially that you want to search backwards, you can use
@c @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r} as
@c a key runs a command (@code{isearch-backward}) to search backward. A
@c backward search finds matches that are entirely before the starting
@c point, just as a forward search finds matches that begin after it.
始めから後向きで探索するのであれば、
@kbd{C-s}のかわりに@kbd{C-r}を使って探索を始めます。
@kbd{C-r}は、後向きに探索するコマンド@code{isearch-backward}を起動します。
前向き探索が開始位置よりうしろにある一致箇所をみつけるのと同様に、
後向き探索は開始位置よりまえにある一致箇所をみつけだします。
@c The characters @kbd{C-y} and @kbd{C-w} can be used in incremental
@c search to grab text from the buffer into the search string. This
@c makes it convenient to search for another occurrence of text at point.
@c @kbd{C-w} copies the character or word after point as part of the
@c search string, advancing point over it. (The decision, whether to
@c copy a character or a word, is heuristic.) Another @kbd{C-s} to
@c repeat the search will then search for a string including that
@c character or word.
インクリメンタルサーチ中には、文字@kbd{C-y}と@kbd{C-w}を使って、
バッファから探索文字列へテキストを取り込むことができます。
この機能は、ポイント位置にあるテキストの出現箇所を探すときに便利です。
@kbd{C-w}は、ポイント以降の文字や単語を探索文字列の一部としてコピーし、
ポイントをその単語の末尾に進めます(文字か単語かは状況によって変わります)。
探索を繰り返す意味で@kbd{C-s}を打つと、
その文字や単語を含んだ文字列を探索します。
@kbd{C-y}も@kbd{C-w}に似ていますが、
現在行の残りの部分をすべて探索文字列にコピーします。
大文字小文字を区別しない探索では、
@kbd{C-y}と@kbd{C-w}はともに、
コピーするテキストを小文字だけに変換します。
@c The character @kbd{M-y} copies text from the kill ring into the search
@c string. It uses the same text that @kbd{C-y} as a command would yank.
@kbd{Mouse-2} in the echo area does the same.
@xref{Yanking}.
文字@kbd{M-y}は、キルリングから探索文字列にテキストをコピーします。
これには、ヤンクコマンド@kbd{C-y}がヤンクするのと
同じテキストを用います。エコー領域で @kbd{Mouse-2} としても同様のことができます.
@xref{Yanking}。
@c When you exit the incremental search, it sets the mark to where point
@c @emph{was}, before the search. That is convenient for moving back
@c there. In Transient Mark mode, incremental search sets the mark without
@c activating it, and does so only if the mark is not already active.
インクリメンタルサーチを終了すると、
探索開始前にポイントが@emph{あった}位置にマークを置きます。
これにより容易にその位置に戻れます。
暫定マーク(transient-mark)モードでは、
マークが不活性のときに限って、
インクリメンタルサーチが設定するマークも不活性です。
@cindex lazy search highlighting
@vindex isearch-lazy-highlight
@c When you pause for a little while during incremental search, it
@c highlights all other possible matches for the search string. This
@c makes it easier to anticipate where you can get to by typing @kbd{C-s}
@c or @kbd{C-r} to repeat the search. The short delay before highlighting
@c other matches helps indicate which match is the current one.
@c If you don't like this feature, you can turn it off by setting
@c @code{isearch-lazy-highlight} to @code{nil}.
インクリメンタルサーチ中に少し中断すると,一致するすべての候補が強調表示されます.
これにより,次に @kbd{C-s} や @kbd{C-r} をした時にどこに移動するかが分かります.
強調表示するまでに多少遅れがありますので,現在の一致箇所もすぐに分かります.この
ような遅れが無い方がいい場合には @code{isearch-lazy-highlight} を @code{nil} に
設定します.
@vindex isearch-lazy-highlight-face
@cindex faces for highlighting search matches
@c You can control how this highlighting looks by customizing the faces
@c @code{isearch} (used for the current match) and
@c @code{isearch-lazy-highlight-face} (for all the other matches).
通常の一致箇所のフェイスは @code{isearch},その他のすべての一致箇所に使われるフェ
イスは @code{isearch-lazy-highlight-face} でカスタマイズできます.
@vindex isearch-mode-map
@c To customize the special characters that incremental search understands,
@c alter their bindings in the keymap @code{isearch-mode-map}. For a list
@c of bindings, look at the documentation of @code{isearch-mode} with
@c @kbd{C-h f isearch-mode @key{RET}}.
インクリメンタルサーチ中に用いる特別な文字をカスタマイズするには、
キーマップ@code{isearch-mode-map}中のバインディングを変更します。
バインディング一覧は、@kbd{C-h f isearch-mode @key{RET}}を使って
@code{isearch-mode}に関する説明文を参照してください。
@c @subsection Scrolling During Incremental Search
@subsection インクリメンタルサーチ中のスクロール @emph{(2004/03/25)}
@c Vertical scrolling during incremental search can be enabled by
@c setting the customizable variable @code{isearch-allow-scroll} to a
@c non-nil value.
@code{isearch-allow-scroll} を non-nil に設定することでインクリメンタルサーチ中
にスクロールできるようになります.
@c You can then use the vertical scroll-bar or certain keyboard
@c commands such as @kbd{@key{PRIOR}} (@code{scroll-down}),
@c @kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter})
@c within the search, thus letting you see more of the text near the
@c current match. You must run these commands via their key sequences to
@c stay in the search - typing M-x @var{comand-name} will always
@c terminate a search.
検索中に縦方向のスクロールバーや @kbd{@key{PRIOR}} (@code{scroll-down}) や
@kbd{@key{NEXT}} (@code{scroll-up}),@kbd{C-l} (@code{recenter}) といった一部の
キーバインドを利用できるようになります.これにより,現在の一致箇所付近でもっと広
い箇所を見ることができます.ただし,検索を中断させないためにはこれらのキーバイン
ドを使わないといけません.M-x @var{comand-name} を使うと必ず検索を中断します.
@c You can give prefix arguments to these commands in the usual way.
@c The current match cannot be scrolled out of the window - this is
@c intentional.
通常の方法で前置引数を与えることができます.現在の一致箇所がウィンドウ外になるよ
うなスクロールはできません.
@c Several other commands, such as @kbd{C-x 2}
@c (@code{split-window-vertically}) and @kbd{C-x ^}
@c (@code{enlarge-window}) which don't scroll the window, are
@c nevertheless made available under this rubric, since they are likewise
@c handy during a search.
@kbd{C-x 2} (@code{split-window-vertically}) や @kbd{C-x ^}
(@code{enlarge-window}) のようなコマンドはウィンドウはスクロールさせません.しか
し,検索中に利用できると便利なため,これらのコマンドも検索中に利用できます.
@c For a list of commands which are configured as scrolling commands by
@c default and instructions on how thus to configure other commands, see
@c @ref{Configuring Scrolling}.
デフォルトでスクロールさせるコマンド(検索中に利用できるコマンド)として設定されて
いるものの一覧や他のコマンドを設定する方法は @ref{Configuring Scrolling} を参照
ください.
@c @subsection Slow Terminal Incremental Search
@subsection 低速端末でのインクリメンタルサーチ @emph{(2004/03/26)}
@c Incremental search on a slow terminal uses a modified style of display
@c that is designed to take less time. Instead of redisplaying the buffer at
@c each place the search gets to, it creates a new single-line window and uses
@c that to display the line that the search has found. The single-line window
@c comes into play as soon as point moves outside of the text that is already
@c on the screen.
速度の遅い端末でのインクリメンタルサーチでは、
表示時間が少なくてすむように設計された表示形式を使います。
みつけた箇所でバッファを再表示するかわりに、
新たに1行分のウィンドウを作ってそこにみつけた行を表示します。
この1行分のウィンドウは、
探索することでポイントが画面に表示中のテキストから
飛び出た時点で使われます。
@c When you terminate the search, the single-line window is removed.
@c Emacs then redisplays the window in which the search was done, to show
@c its new position of point.
探索を終了すると、この1行分のウィンドウは消えます。
そして、Emacsは探索を完了したウィンドウを再表示して、
新たなポイント位置を示します。
@ignore
@c The three dots at the end of the search string, normally used to indicate
@c that searching is going on, are not displayed in slow style display.
探索中であることを示すために探索文字列の末尾に3つの点
(@dots{})を通常表示しますが、低速向けの表示形式では表示しません。
@end ignore
@vindex search-slow-speed
@c The slow terminal style of display is used when the terminal baud rate is
@c less than or equal to the value of the variable @code{search-slow-speed},
@c initially 1200. See @code{baud-rate} in @ref{Display Custom}.
低速向けの表示形式を使うのは、
端末のボーレートが変数@code{search-slow-speed}の値以下である場合で、
その初期値は1200です。@ref{Display Custom} の @code{baud-rate} を参照ください.
@vindex search-slow-window-lines
@c The number of lines to use in slow terminal search display is controlled
@c by the variable @code{search-slow-window-lines}. Its normal value is 1.
低速向けの表示形式に使う表示用ウィンドウの行数は、
変数@code{search-slow-window-lines}で制御します。
通常の値は1です。
@node Nonincremental Search, Word Search, Incremental Search, Search
@c @section Nonincremental Search
@section 一括型探索
@c @cindex nonincremental search
@cindex 一括型探索
@c Emacs also has conventional nonincremental search commands, which require
@c you to type the entire search string before searching begins.
Emacsでは、従来方式の一括型探索コマンドもあります。
探索を開始するまえに探索文字列全体を打っておく必要があります。
@table @kbd
@item C-s @key{RET} @var{string} @key{RET}
@c Search for @var{string}.
@var{string}を探索する。
@item C-r @key{RET} @var{string} @key{RET}
@c Search backward for @var{string}.
@var{string}を後向きに探索する。
@end table
@c To do a nonincremental search, first type @kbd{C-s @key{RET}}. This
@c enters the minibuffer to read the search string; terminate the string
@c with @key{RET}, and then the search takes place. If the string is not
@c found, the search command signals an error.
一括型探索を実行するには、まず@kbd{C-s @key{RET}}と打ちます。
すると、探索文字列を読み取るためにミニバッファに移動します。
文字列を@key{RET}で終えると、探索を開始します。
文字列がみつからなければ、探索コマンドはエラーを表示します。
@c When you type @kbd{C-s @key{RET}}, the @kbd{C-s} invokes incremental
@c search as usual. That command is specially programmed to invoke
@c nonincremental search, @code{search-forward}, if the string you
@c specify is empty. (Such an empty argument would otherwise be
@c useless.) But it does not call @code{search-forward} right away. First
@c it checks the next input character to see if is @kbd{C-w},
@c which specifies a word search.
@kbd{C-s @key{RET}} はつぎのように動作します。
まず、@kbd{C-s}がいつものようにインクリメンタルサーチを起動します。
インクリメンタルサーチは、特別な場合として、
引数が空であったときには一括型探索(@code{search-forward})を起動するようにプログラムしてあります。
(さもなければ、そのような空の引数に意味はない).
しかし、@kbd{C-s @key{RET}}で実行される一括型探索は、
@code{search-forward}をただちに呼び出すわけではありません。
まず、つぎの文字が単語探索を指示する@kbd{C-w}であるかどうか調べます。
@ifinfo
@c @xref{Word Search}.
@xref{Word Search}。
@end ifinfo
@c @kbd{C-r @key{RET}} does likewise, for a reverse incremental search.
@kbd{C-r @key{RET}} も逆方向のインクリメンタルサーチとして同様に機能し
ます.
@findex search-forward
@findex search-backward
@c Forward and backward nonincremental searches are implemented by the
@c commands @code{search-forward} and @code{search-backward}. These
@c commands may be bound to keys in the usual manner. The feature that you
@c can get to them via the incremental search commands exists for
@c historical reasons, and to avoid the need to find key sequences
@c for them.
前向き/後向きの一括型探索は、
コマンド@code{search-forward}と@code{search-backward}で実装されています。
これらのコマンドは通常と同じようにキーにバインドできます。
インクリメンタルサーチコマンドから呼び出せるようになっているのは、
歴史的な理由、および、
キー列を選ぶ労力を削減できるという理由からです。
@node Word Search, Regexp Search, Nonincremental Search, Search
@c @section Word Search
@section 単語探索
@c @cindex word search
@cindex 単語探索
@c Word search searches for a sequence of words without regard to how the
@c words are separated. More precisely, you type a string of many words,
@c using single spaces to separate them, and the string can be found even
@c if there are multiple spaces, newlines, or other punctuation characters
@c between these words.
単語探索は、単語の区切られ方を無視して、単語の列を探索します。
より正確には、空白1個で区切った数個の単語を打ち込むと、
単語と単語のあいだに複数個の空白/改行/句読点があったとしても、
それらの文字列をみつけだすことができます。
@c Word search is useful for editing a printed document made with a text
@c formatter. If you edit while looking at the printed, formatted version,
@c you can't tell where the line breaks are in the source file. With word
@c search, you can search without having to know them.
単語探索は、テキスト清書系で整形済みの文書を編集する場合に便利です。
整形した印刷出力を見ながら編集する場合、
ソースファイルのどこで行が区切られているのかわかりません。
単語探索を使えば、単語の区切られ方を知らなくても探索できます。
@table @kbd
@item C-s @key{RET} C-w @var{words} @key{RET}
@c Search for @var{words}, ignoring details of punctuation.
句読点などの詳細は無視して、@var{words}を探索する。
@item C-r @key{RET} C-w @var{words} @key{RET}
@c Search backward for @var{words}, ignoring details of punctuation.
句読点などの詳細は無視して、後向きに@var{words}を探索する。
@end table
@c Word search is a special case of nonincremental search and is invoked
@c with @kbd{C-s @key{RET} C-w}. This is followed by the search string,
@c which must always be terminated with @key{RET}. Being nonincremental,
@c this search does not start until the argument is terminated. It works
@c by constructing a regular expression and searching for that; see
@c @ref{Regexp Search}.
単語探索は、一括型探索の特別な場合であって、
@kbd{C-s @key{RET} C-w}で起動します。
この入力に続いて、探索文字列を入力し、
文字列はつねに@key{RET}で終えます。
一括型であるため、単語探索も引数を入力し終えるまで探索を開始しません。
単語探索は、正規表現を構築し、その正規表現で探索を行うことで
動作します。
@xref{Regexp Search}。
@c Use @kbd{C-r @key{RET} C-w} to do backward word search.
後向きの単語探索には@kbd{C-r @key{RET} C-w}を使います。
@findex word-search-forward
@findex word-search-backward
@c Forward and backward word searches are implemented by the commands
@c @code{word-search-forward} and @code{word-search-backward}. These
@c commands may be bound to keys in the usual manner. They are available
@c via the incremental search commands both for historical reasons and
@c to avoid the need to find suitable key sequences for them.
前向き/後向きの単語探索は、それぞれ、
コマンド@code{word-search-forward}と@code{word-search-backward}で
実装されています。
これらのコマンドは通常どおりキーに割り当てることができます。
インクリメンタルサーチコマンドから呼び出せるようになっているのは、
歴史的な理由、および、
これらの機能にふさわしいキー列を選ぶ労力を削減できるという理由からです。
@node Regexp Search, Regexps, Word Search, Search
@c @section Regular Expression Search
@section 正規表現探索
@c @cindex regular expression
@cindex 正規表現
@cindex regexp
@c A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern
@c that denotes a class of alternative strings to match, possibly
@c infinitely many. GNU Emacs provides both incremental and
@c nonincremental ways to search for a match for a regexp.
@dfn{正規表現}(regular expression、@dfn{regexp}と略す)とは、
一致する可能性がある一連の(無限個でもよい)文字列を表現するパターンです。
GNU Emacsでは、インクリメンタルサーチでも一括型探索でも、
正規表現を用いた探索ができます。
@kindex C-M-s
@findex isearch-forward-regexp
@kindex C-M-r
@findex isearch-backward-regexp
@c Incremental search for a regexp is done by typing @kbd{C-M-s}
@c (@code{isearch-forward-regexp}), or by invoking @kbd{C-s} with a
@c prefix argument (whose value does not matter). This command reads a
@c search string incrementally just like @kbd{C-s}, but it treats the
@c search string as a regexp rather than looking for an exact match
@c against the text in the buffer. Each time you add text to the search
@c string, you make the regexp longer, and the new regexp is searched
@c for. To search backward for a regexp, use @kbd{C-M-r}
@c (@code{isearch-backward-regexp}), or @kbd{C-r} with a prefix argument.
正規表現によるインクリメンタルサーチを実行するには、
@kbd{C-M-s}(@code{isearch-forward-regexp})と打つか,(値は関係ない)
前置引数を指定して@kbd{C-s}を起動します。
このコマンドは、@kbd{C-s}と同様に、探索文字列を逐次読み取ります。
ただし、探索文字列をバッファのテキストに対して正確に照合するため
のものとみなすのではなく、正規表現として扱います。
探索文字列にテキストを追加するごとに、
正規表現は長くなり、新たな正規表現を探索します。
後向きに正規表現を探索するには、
@kbd{C-M-r}(@code{isearch-backward-regexp})を使うか、
前置引数を指定して@kbd{C-r}を使います。
@c All of the control characters that do special things within an
@c ordinary incremental search have the same function in incremental regexp
@c search. Typing @kbd{C-s} or @kbd{C-r} immediately after starting the
@c search retrieves the last incremental search regexp used; that is to
@c say, incremental regexp and non-regexp searches have independent
@c defaults. They also have separate search rings that you can access with
@c @kbd{M-p} and @kbd{M-n}.
通常のインクリメンタルサーチにおいて特別な機能を持つコントロール文字は、
正規表現のインクリメンタルサーチでも同じ機能を持ちます。
探索の開始直後に@kbd{C-s}や@kbd{C-r}を打つと、
最後のインクリメンタルサーチに用いた正規表現を再度使います。
つまり、正規表現を用いる探索とそうでない探索とには、
それぞれ独立のデフォルトがあるのです。
@kbd{M-p}と@kbd{M-n}で参照できる探索リングも
それぞれ別々です。
@c If you type @key{SPC} in incremental regexp search, it matches any
@c sequence of whitespace characters, including newlines. If you want
@c to match just a space, type @kbd{C-q @key{SPC}}.
正規表現のインクリメンタルサーチで@key{SPC}を打つと、
改行を含めた任意個の白文字に一致します。
ちょうど1個の空白に一致させたいのであれば、
@kbd{C-q @key{SPC}}と打ちます。
@c Note that adding characters to the regexp in an incremental regexp
@c search can make the cursor move back and start again. For example, if
@c you have searched for @samp{foo} and you add @samp{\|bar}, the cursor
@c backs up in case the first @samp{bar} precedes the first @samp{foo}.
正規表現のインクリメンタルサーチ中に正規表現に文字を加えると、
カーソルをもとに戻して探索し直すことがあります。
たとえば、@samp{foo}を探索し終えたときに@samp{\|bar}を追加したとします。
最初の@samp{bar}が最初の@samp{foo}に先行する場合には、
カーソルはまえに戻ります。
@findex re-search-forward
@findex re-search-backward
@c Nonincremental search for a regexp is done by the functions
@c @code{re-search-forward} and @code{re-search-backward}. You can invoke
@c these with @kbd{M-x}, or bind them to keys, or invoke them by way of
@c incremental regexp search with @kbd{C-M-s @key{RET}} and @kbd{C-M-r
@c @key{RET}}.
正規表現の一括型探索は、関数@code{re-search-forward}と
@code{re-search-backward}で行われます。
これらは、@kbd{M-x}で呼び出したり、キーに割り当てたり、あるいは、
@kbd{C-M-s @key{RET}}や@kbd{C-M-r @key{RET}}として
正規表現のインクリメンタルサーチの方法で起動したりできます。
@c If you use the incremental regexp search commands with a prefix
@c argument, they perform ordinary string search, like
@c @code{isearch-forward} and @code{isearch-backward}. @xref{Incremental
@c Search}.
正規表現のインクリメンタルサーチコマンドに前置引数を指定すると、
@code{isearch-forward}や@code{isearch-backward}のように、
普通の文字列探索を行います。
@xref{Incremental Search}。
@node Regexps, Search Case, Regexp Search, Search
@c @section Syntax of Regular Expressions
@section 正規表現の構文 @emph{(2004/03/26)}
@c @cindex syntax of regexps
@cindex regexpの構文
@c This manual describes regular expression features that users
@c typically want to use. There are additional features that are
@c mainly used in Lisp programs; see @ref{Regular Expressions,,,
@c elisp, the same manual}.
このマニュアルではよく使われる正規表現について説明しています.主にリス
プのプログラムで使われる追加機能については @ref{Regular
Expressions,,,elisp, the same manual} を参照してください.
@c Regular expressions have a syntax in which a few characters are
@c special constructs and the rest are @dfn{ordinary}. An ordinary
@c character is a simple regular expression which matches that same
@c character and nothing else. The special characters are @samp{$},
@c @samp{^}, @samp{.}, @samp{*}, @samp{+}, @samp{?}, @samp{[}, @samp{]} and
@c @samp{\}. Any other character appearing in a regular expression is
@c ordinary, unless a @samp{\} precedes it. (When you use regular
@c expressions in a Lisp program, each @samp{\} must be doubled, see the
@c example near the end of this section.)
正規表現には、特別な使い方をする少数の文字と
その他の@dfn{普通の}文字から成る構文があります。
普通の文字は、
同じ文字だけに一致してそれ以外には一致しない単純な正規表現です。
特別な文字は、@samp{$}、@samp{^}、@samp{.}、@samp{*}、@samp{+}、
@samp{?}、@samp{[}、@samp{]}、および、@samp{\}です。
@samp{\}が先行する場合を除いて、
正規表現に現れるこれら以外の文字は普通の文字です(正規表現をリスプコー
ド内で使う場合には @samp{\} が倍必要になります.具体的には,この章の終わりにあるサ
ンプルを参照してください)。
@c For example, @samp{f} is not a special character, so it is ordinary, and
@c therefore @samp{f} is a regular expression that matches the string
@c @samp{f} and no other string. (It does @emph{not} match the string
@c @samp{ff}.) Likewise, @samp{o} is a regular expression that matches
@c only @samp{o}. (When case distinctions are being ignored, these regexps
@c also match @samp{F} and @samp{O}, but we consider this a generalization
@c of ``the same string,'' rather than an exception.)
たとえば、@samp{f}は特別な文字ではなく、通常の文字ですから、
文字列@samp{f}に一致してそれ以外の文字列には一致しない正規表現です。
(これは、文字列@samp{ff}には一致し@emph{ない}。)
同様に、@samp{o}は、@samp{o}だけに一致する正規表現です。
(大文字小文字を区別しない場合、
これらの正規表現は@samp{F}や@samp{O}にも一致するが、
これらは例外というよりは、『同じ文字列』の一般化として捉える。)
@c Any two regular expressions @var{a} and @var{b} can be concatenated. The
@c result is a regular expression which matches a string if @var{a} matches
@c some amount of the beginning of that string and @var{b} matches the rest of
@c the string.@refill
任意の2つの正規表現@var{a}と@var{b}を連結できます。
その結果は、@var{a}が文字列の始めの適当な部分に一致して、かつ、
@var{b}が文字列の残りの部分に一致する場合に、
文字列に一致するような正規表現です。
@c As a simple example, we can concatenate the regular expressions @samp{f}
@c and @samp{o} to get the regular expression @samp{fo}, which matches only
@c the string @samp{fo}. Still trivial. To do something nontrivial, you
@c need to use one of the special characters. Here is a list of them.
簡単な例として、正規表現@samp{f}と@samp{o}を連結すると、
正規表現@samp{fo}を得ますが、
これは文字列@samp{fo}だけに一致します。
簡単ですね。
多少とも複雑なことを行うには、特別な文字を使う必要があります。
以下にその一覧をあげます。
@table @asis
@c @item @kbd{.}@: @r{(Period)}
@item @kbd{.}@: @r{(ピリオド)}
@c is a special character that matches any single character except a newline.
@c Using concatenation, we can make regular expressions like @samp{a.b}, which
@c matches any three-character string that begins with @samp{a} and ends with
@c @samp{b}.@refill
特別な文字であり、改行以外の任意の1文字に一致する。
連結を使って@samp{a.b}のような正規表現を作れる。
これは、@samp{a}で始まり@samp{b}で終る任意の3文字の文字列に一致する。
@item @kbd{*}
@c is not a construct by itself; it is a postfix operator that means to
@c match the preceding regular expression repetitively as many times as
@c possible. Thus, @samp{o*} matches any number of @samp{o}s (including no
@c @samp{o}s).
単独では構成要素ではない。
直前の正規表現を可能な限り反復することを意味する後置演算子である。
すなわち、(@samp{o}が存在しない場合も含めて)
@samp{o*}は任意個の@samp{o}に一致する。
@c @samp{*} always applies to the @emph{smallest} possible preceding
@c expression. Thus, @samp{fo*} has a repeating @samp{o}, not a repeating
@c @samp{fo}. It matches @samp{f}, @samp{fo}, @samp{foo}, and so on.
@samp{*}はつねに先行する@emph{最小}の正規表現に適用される。
したがって、@samp{fo*}は@samp{fo}を繰り返すのではなく、
@samp{o}を繰り返す。
この正規表現は@samp{f}、@samp{fo}、@samp{foo}などに一致する。
@c The matcher processes a @samp{*} construct by matching, immediately,
@c as many repetitions as can be found. Then it continues with the rest
@c of the pattern. If that fails, backtracking occurs, discarding some
@c of the matches of the @samp{*}-modified construct in case that makes
@c it possible to match the rest of the pattern. For example, in matching
@c @samp{ca*ar} against the string @samp{caaar}, the @samp{a*} first
@c tries to match all three @samp{a}s; but the rest of the pattern is
@c @samp{ar} and there is only @samp{r} left to match, so this try fails.
@c The next alternative is for @samp{a*} to match only two @samp{a}s.
@c With this choice, the rest of the regexp matches successfully.@refill
@samp{*}を用いた構成は、一致を処理するときには、
ただちに得られる限りの反復回数に展開される。
そうしてから、残りのパターンを処理する。
一致に失敗すると、バックトラック(後戻り)が発生して、
@samp{*}を用いた構成の反復回数を減らして、
パターンの残りの部分が一致するようにする。
たとえば、文字列@samp{caaar}に対して
@samp{ca*ar}を一致させることを考えてみる。
始めに、@samp{a*}を3つの@samp{a}すべてに一致させようとする。
しかし、残りのパターンが@samp{ar}なのに@samp{r}しか残っていないため、
この試みは失敗する。
そこで、つぎは@samp{a*}を@samp{a}2つだけに一致させる。
こうすると、残りの正規表現も正しく一致する。
@item @kbd{+}
@c is a postfix operator, similar to @samp{*} except that it must match
@c the preceding expression at least once. So, for example, @samp{ca+r}
@c matches the strings @samp{car} and @samp{caaaar} but not the string
@c @samp{cr}, whereas @samp{ca*r} matches all three strings.
@samp{*}に似た後置演算子だが、
直前の正規表現に1回以上一致する必要がある。
たとえば、@samp{ca+r}は、文字列@samp{car}や@samp{caaaar}には一致するが、
文字列@samp{cr}には一致ない。
@samp{ca*r}の場合は、上記の3つすべてに一致する。
@item @kbd{?}
@c is a postfix operator, similar to @samp{*} except that it can match the
@c preceding expression either once or not at all. For example,
@c @samp{ca?r} matches @samp{car} or @samp{cr}; nothing else.
@samp{*}に似た後置演算子だが、
直前の正規表現に1回だけ一致するか、あるいは、1回も一致しない。
たとえば、@samp{ca?r}は、@samp{car}や@samp{cr}に一致するが、
他のものには一致しない。
@item @kbd{*?}, @kbd{+?}, @kbd{??}
@cindex non-greedy regexp matching
@c are non-greedy variants of the operators above. The normal operators
@c @samp{*}, @samp{+}, @samp{?} are @dfn{greedy} in that they match as
@c much as they can, as long as the overall regexp can still match. With
@c a following @samp{?}, they are non-greedy: they will match as little
@c as possible.
上記は最小一致の(non-greedy,貪欲でない)演算子である.@samp{*},
@samp{+}, @samp{?} のような普通の演算子は @dfn{greedy} (貪欲,最長一致)
である.つまり,正規表現に対してできる限り長い文字が一致する.@samp{?}
を付加すると貪欲でない最小一致にになるので,最小の部分が一致する.
@c Thus, both @samp{ab*} and @samp{ab*?} can match the string @samp{a}
@c and the string @samp{abbbb}; but if you try to match them both against
@c the text @samp{abbb}, @samp{ab*} will match it all (the longest valid
@c match), while @samp{ab*?} will match just @samp{a} (the shortest
@c valid match).
つまり,@samp{ab*} と @samp{ab*?} は両方とも @samp{a} に一致するし,
@samp{abbbb} にも一致できる.しかし,@samp{abbbb} に対して両者の正規表
現をためしてみると,@samp{ab*}ではすべての部分(最長一致)が一致するのに
対して,@samp{ab*?} では @samp{a} だけ(最小一致)が一致する.
@c Non-greedy operators match the shortest possible string starting at a
@c given starting point; in a forward search, though, the earliest
@c possible starting point for match is always the one chosen. Thus, if
@c you search for @samp{a.*?$} against the text @samp{abbab} followed by
@c a newline, it matches the whole string. Since it @emph{can} match
@c starting at the first @samp{a}, it does.
最小一致の演算子は開始点以降でできる限り短い部分に一致するように検索を
行う.順方向の検索では一致する最も近い位置は常にカーソルの場所である.
それゆえ,@samp{a.*?$} を 改行に続く @samp{abbab} に対して検索すると全
体に一致する.最初の@samp{a}に一致するので,これが可能になる.
@item @kbd{\@{@var{n}\@}}
@c is a postfix operator that specifies repetition @var{n} times---that
@c is, the preceding regular expression must match exactly @var{n} times
@c in a row. For example, @samp{x\@{4\@}} matches the string @samp{xxxx}
@c and nothing else.
は @var{n} 回の繰り返しを表す後置演算子である.つまり,後に続く正規表現をちょう
ど @var{n} 回繰り返す文字に一致する.例えば,@samp{x\@{4\@}} は @samp{xxxx} に一
致する.
@item @kbd{\@{@var{n},@var{m}\@}}
@c is a postfix operator that specifies repetition between @var{n} and
@c @var{m} times---that is, the preceding regular expression must match
@c at least @var{n} times, but no more than @var{m} times. If @var{m} is
@c omitted, then there is no upper limit, but the preceding regular
@c expression must match at least @var{n} times.@* @samp{\@{0,1\@}} is
@c equivalent to @samp{?}. @* @samp{\@{0,\@}} is equivalent to
@c @samp{*}. @* @samp{\@{1,\@}} is equivalent to @samp{+}.
は後置的な演算子である.@var{n} 〜 @var{m} 回繰り返すことを意味する.
つまり,すくなくとも @var{n} 回は正規表現が一致しなければならず,
@var{m} 回を超えてもいけない.もし @var{m} を指定しなければ,上限が無
くなるが,すくなくとも @var{n} 回は一致しなければならない.@*
@samp{\@{0,1\@}} は @samp{?} と同じである.@* @samp{\@{0,\@}} は
@samp{*} と同じである.@* @samp{\@{1,\@}} は @samp{+} と同じになる.
@item @kbd{[ @dots{} ]}
@c is a @dfn{character set}, which begins with @samp{[} and is terminated
@c by @samp{]}. In the simplest case, the characters between the two
@c brackets are what this set can match.
@samp{[}で始まり@samp{]}で終る@dfn{文字集合}を表す。
もっとも単純な場合は、
この2つの中括弧のあいだにある文字の1つ1つがこの文字集合に一致する。
@c Thus, @samp{[ad]} matches either one @samp{a} or one @samp{d}, and
@c @samp{[ad]*} matches any string composed of just @samp{a}s and @samp{d}s
@c (including the empty string), from which it follows that @samp{c[ad]*r}
@c matches @samp{cr}, @samp{car}, @samp{cdr}, @samp{caddaar}, etc.
したがって、@samp{[ad]}は、@samp{a}1文字か@samp{d}1文字のどちらにも一致する。
@samp{[ad]*}は、@samp{a}と@samp{d}だけから成る
(空の文字列を含む)任意の文字列に一致する。
このことから、@samp{c[ad]*r}は、
@samp{cr}、@samp{car}、@samp{cdr}、@samp{caddaar}などに一致することがわかる。
@c You can also include character ranges in a character set, by writing the
@c starting and ending characters with a @samp{-} between them. Thus,
@c @samp{[a-z]} matches any lower-case @acronym{ASCII} letter. Ranges may be
@c intermixed freely with individual characters, as in @samp{[a-z$%.]},
@c which matches any lower-case @acronym{ASCII} letter or @samp{$}, @samp{%} or
@c period.
文字集合には、文字範囲の指定を含めることもでき、
始めの文字と終りの文字のあいだに@samp{-}を書く。
つまり、@samp{[a-z]}はすべての @acronym{ASCII} 小文字に一致する。
範囲指定と個々の文字を自由に織り混ぜてよく、
@samp{[a-z$%.]}のように書ける。
これは、任意の @acronym{ASCII} の小文字、@samp{$}、@samp{%}、ピリオドに一致する。
@c Note that the usual regexp special characters are not special inside a
@c character set. A completely different set of special characters exists
@c inside character sets: @samp{]}, @samp{-} and @samp{^}.
文字集合の内側では、正規表現の通常の特別な文字を
特別扱いしないことに注意。
文字集合の内側では、まったく別の特別な文字、
@samp{]}、@samp{-}、および @samp{^} が存在する。
@c To include a @samp{]} in a character set, you must make it the first
@c character. For example, @samp{[]a]} matches @samp{]} or @samp{a}. To
@c include a @samp{-}, write @samp{-} as the first or last character of the
@c set, or put it after a range. Thus, @samp{[]-]} matches both @samp{]}
@c and @samp{-}.
文字集合に@samp{]}を含めるには、
@samp{]}を最初の文字として指定する必要がある。
たとえば、@samp{[]a]}は、@samp{]}や@samp{a}に一致する。
@samp{-}を含めるのであれば、@samp{-}を文字集合の最初の文字か
最後の文字として指定して、範囲指定のあとに置く。
したがって、@samp{[]-]}は、@samp{]}と@samp{-}の両方に一致する。
@c To include @samp{^} in a set, put it anywhere but at the beginning of
@c the set. (At the beginning, it complements the set---see below.)
文字集合に@samp{^}を含めるには、@samp{^}を文字集合の2番目以降に置く(最
初に置くと,それは集合に補足するようになる.以下を参照)。