OSDN Git Service

bcbe5060ed96c4b6aad857b68530c25824f6c9cc
[linuxjm/LDP_man-pages.git] / draft / man3 / regex.3
1 .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Wed Jun 14 16:10:28 BST 1995 Wilf. (G.Wilford@ee.surrey.ac.uk)
24 .\" Tiny change in formatting - aeb, 950812
25 .\" Modified 8 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
26 .\"
27 .\" Japanese Version Copyright (c) 1998 Takatsugu Nokubi
28 .\"     all rights reserved.
29 .\" Translated 1998-06-30, Takatsugu Nokubi
30 .\" Updated & Modified 2001-11-05, Yuichi SATO <ysato@h4.dion.ne.jp>
31 .\" Updated & Modified 2005-02-24, Yuichi SATO <ysato444@yahoo.co.jp>
32 .\" Updated 2008-08-02, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
33 .\"
34 .\"WORD:        bitwise-or              ビットごとのOR
35 .\"WORD:        element                 (構造体)要素
36 .\"WORD:        collating element       照合順序の要素
37 .\"
38 .\" show the synopsis section nicely
39 .de xx
40 .in \\n(INu+\\$1
41 .ti -\\$1
42 ..
43 .TH REGEX 3 2011-09-27 "GNU" "Linux Programmer's Manual"
44 .\"O .SH NAME
45 .SH 名前
46 .\"O regcomp, regexec, regerror, regfree \- POSIX regex functions
47 regcomp, regexec, regerror, regfree \- POSIX regex 関数
48 .\"O .SH SYNOPSIS
49 .SH 書式
50 .nf
51 .B #include <sys/types.h>
52 .B #include <regex.h>
53
54 .BI "int regcomp(regex_t *" preg ", const char *" regex ", int " cflags );
55
56 .BI "int regexec(const regex_t *" preg ", const char *" string \
57 ", size_t " nmatch ,
58 .BI "            regmatch_t " pmatch[] ", int " eflags );
59
60 .BI "size_t regerror(int " errcode ", const regex_t *" preg ", char *" errbuf ,
61 .BI "                size_t " errbuf_size );
62
63 .BI "void regfree(regex_t *" preg );
64 .fi
65 .\"O .SH DESCRIPTION
66 .SH 説明
67 .\"O .SS "POSIX Regex Compiling"
68 .SS "POSIX regex コンパイル"
69 .\"O .BR regcomp ()
70 .\"O is used to compile a regular expression into a form that is suitable
71 .\"O for subsequent
72 .\"O .BR regexec ()
73 .\"O searches.
74 .BR regcomp ()
75 は、正規表現をコンパイルして、
76 .BR regexec ()
77 での検索処理に適合する形態にする。
78
79 .\"O .BR regcomp ()
80 .\"O is supplied with
81 .\"O .IR preg ,
82 .\"O a pointer to a pattern buffer storage area;
83 .\"O .IR regex ,
84 .\"O a pointer to the null-terminated string and
85 .\"O .IR cflags ,
86 .\"O flags used to determine the type of compilation.
87 .BR regcomp ()
88 はパターンを記憶するバッファへのポインタ
89 .IR preg 、
90 ヌル文字で終端された文字列
91 .IR regex 、
92 そしてコンパイルの形式を決めるためのフラグ
93 .I cflag
94 を引数に伴う。
95
96 .\"O All regular expression searching must be done via a compiled pattern
97 .\"O buffer, thus
98 .\"O .BR regexec ()
99 .\"O must always be supplied with the address of a
100 .\"O .BR regcomp ()
101 .\"O initialized pattern buffer.
102 全ての正規表現検索は、コンパイルされたパターンによって行わなければならない。
103 よって、
104 .BR regexec ()
105 に指定するのは、必ず
106 .RB ( regcomp ()
107 によってコンパイルされた) パターンバッファへのアドレスでなければならない。
108
109 .\"O .I cflags
110 .\"O may be the
111 .\"O .RB bitwise- or
112 .\"O of one or more of the following:
113 .I cflags
114 には以下に示す定数一つ以上のビットごとの OR (bitwise-or) を指定する。
115 .TP
116 .B REG_EXTENDED
117 .\"O Use
118 .\"O .B POSIX
119 .\"O Extended Regular Expression syntax when interpreting
120 .\"O .IR regex .
121 .\"O If not set,
122 .\"O .B POSIX
123 .\"O Basic Regular Expression syntax is used.
124 .I regex
125
126 .B POSIX
127 拡張正規表現を使用する。もしこのフラグが設定されない場合、
128 .B POSIX
129 標準正規表現が使われる。
130 .TP
131 .B REG_ICASE
132 .\"O Do not differentiate case.
133 .\"O Subsequent
134 .\"O .BR regexec ()
135 .\"O searches using this pattern buffer will be case insensitive.
136 大文字小文字の違いを無視する。このフラグを指定してコンパイルされた
137 パターンバッファを用いて
138 .BR regexec ()
139 関数を呼び出すと、大文字小文字の区別を付けずに検索が行われる。
140 .TP
141 .B REG_NOSUB
142 .\"O Support for substring addressing of matches is not required.
143 .\"O The
144 .\"O .I nmatch
145 .\"O and
146 .\"O .I pmatch
147 .\"O arguments to
148 .\"O .BR regexec ()
149 .\"O are ignored if the pattern buffer supplied was compiled with this flag set.
150 このフラグを設定してコンパイルされたパターンバッファが
151 .BR regexec ()
152 の引数に指定されると、引き数
153 .IR nmatch ,
154 .I pmatch
155 が無視される。
156 .TP
157 .B REG_NEWLINE
158 .\"O Match-any-character operators don't match a newline.
159 全ての文字にマッチするオペレータに改行をマッチさせない。
160
161 .\"O A nonmatching list
162 .\"O .RB ( [^...] )
163 .\"O not containing a newline does not match a newline.
164 改行を含まない非マッチング文字リスト
165 .RB ( [^...] )
166 に改行をマッチさせない。
167
168 .\"O Match-beginning-of-line operator
169 .\"O .RB ( ^ )
170 .\"O matches the empty string immediately after a newline, regardless of
171 .\"O whether
172 .\"O .IR eflags ,
173 .\"O the execution flags of
174 .\"O .BR regexec (),
175 .\"O contains
176 .\"O .BR REG_NOTBOL .
177 .BR regexec ()
178 の実行時に指定するフラグ
179 .I eflags
180
181 .B REG_NOTBOL
182 を含むかどうかにかかわらず、行頭にマッチするオペレータ
183 .RB ( ^ )
184 を改行直後の空文字列にマッチさせる。
185
186 .\"O Match-end-of-line operator
187 .\"O .RB ( $ )
188 .\"O matches the empty string immediately before a newline, regardless of
189 .\"O whether
190 .\"O .I eflags
191 .\"O contains
192 .\"O .BR REG_NOTEOL .
193 .I eflags
194
195 .B REG_NOTEOL
196 を含むかどうかにかかわらず、行末にマッチするオペレータ
197 .RB ( $ )
198 を改行直前の空文字列にマッチさせる。
199 .\"O .SS "POSIX Regex Matching"
200 .SS "POSIX regex マッチング"
201 .\"O .BR regexec ()
202 .\"O is used to match a null-terminated string
203 .\"O against the precompiled pattern buffer,
204 .\"O .IR preg .
205 .BR regexec ()
206 は、
207 プリコンパイルされたパターンバッファ
208 .I preg
209 をヌル文字で終端された文字列にマッチさせる。
210 .\"O .I nmatch
211 .\"O and
212 .\"O .I pmatch
213 .\"O are used to provide information regarding the location of any matches.
214 .I nmatch
215
216 .I pmatch
217 はマッチングの位置に関する情報を取得するのに用いられる。
218 .\"O .I eflags
219 .\"O may be the
220 .\"O .RB bitwise- or
221 .\"O of one or both of
222 .\"O .B REG_NOTBOL
223 .\"O and
224 .\"O .B REG_NOTEOL
225 .\"O which cause changes in matching behavior described below.
226 .I eflags
227 には
228 .B REG_NOTBOL
229
230 .B REG_NOTEOL
231 のどちらか、もしくは両方のビットごとの
232 .BR OR " (bitwise-" or )
233 を指定し、以下で説明するようにマッチング動作を変化させる。
234 .TP
235 .\"O .B REG_NOTBOL
236 .\"O The match-beginning-of-line operator always fails to match (but see the
237 .\"O compilation flag
238 .\"O .B REG_NEWLINE
239 .\"O above)
240 .B REG_NOTBOL
241 行頭にマッチするオペレータは、必ずマッチに失敗する (コンパイル時のフラグ
242 .B REG_NEWLINE
243 の項目も参照)。
244 .\"O This flag may be used when different portions of a string are passed to
245 .\"O .BR regexec ()
246 .\"O and the beginning of the string should not be interpreted as the
247 .\"O beginning of the line.
248 このフラグは、複数行にまたがる文字列を
249 .BR regexec ()
250 で検索する際に、文字列の先頭を行の先頭として解釈させない場合に用いる。
251 .TP
252 .\"O .B REG_NOTEOL
253 .\"O The match-end-of-line operator always fails to match (but see the
254 .\"O compilation flag
255 .\"O .B REG_NEWLINE
256 .\"O above)
257 .B REG_NOTEOL
258 行末にマッチするオペレータは、必ずマッチに失敗する (コンパイル時のフラグ
259 .B REG_NEWLINE
260 の項目も参照)。
261 .\"O .SS "Byte Offsets"
262 .SS バイトオフセット
263 .\"O Unless
264 .\"O .B REG_NOSUB
265 .\"O was set for the compilation of the pattern buffer, it is possible to
266 .\"O obtain substring match addressing information.
267 パターンバッファのコンパイル時に
268 .B REG_NOSUB
269 が設定されない場合は、部分文字列のマッチング位置情報を得ることができる。
270 .\"O .I pmatch
271 .\"O must be dimensioned to have at least
272 .\"O .I nmatch
273 .\"O elements.
274 .I pmatch
275 は、少なくとも
276 .I nmatch
277 の大きさを持つように指定しなければならない。
278 .\"O These are filled in by
279 .\"O .BR regexec ()
280 .\"O with substring match addresses.
281 .\"O Any unused structure elements
282 .\"O will contain the value \-1.
283 .BR regexec ()
284 の実行によって、それらに部分文字列マッチング位置情報が代入される。
285 未使用の構造体要素には \-1 が値として代入される。
286
287 .\"O The
288 .\"O .I regmatch_t
289 .\"O structure which is the type of
290 .\"O .I pmatch
291 .\"O is defined in
292 .\"O .IR <regex.h> .
293 .I pmatch
294 の型である
295 .I regmatch_t
296 構造体は、
297 .I <regex.h>
298 内で定義される。
299
300 .in +4n
301 .nf
302 typedef struct {
303     regoff_t rm_so;
304     regoff_t rm_eo;
305 } regmatch_t;
306 .fi
307 .in
308
309 .\"O Each
310 .\"O .I rm_so
311 .\"O element that is not \-1 indicates the start offset of the next largest
312 .\"O substring match within the string.
313 .\"O The relative
314 .\"O .I rm_eo
315 .\"O element indicates the end offset of the match,
316 .\"O which is the offset of the first character after the matching text.
317 構造体要素
318 .I rm_so
319 の値が \-1 でない場合、それは文字列内での次の最大のマッチング部分の開始
320 オフセット位置を示す。それに対し、構造体要素
321 .I rm_eo
322 はマッチング部分の終了オフセット位置を示し、
323 マッチング部分の直後の文字のオフセット位置が使用される。
324 .\"O .SH "POSIX Error Reporting"
325 .SS "POSIX エラーレポート"
326 .\"O .BR regerror ()
327 .\"O is used to turn the error codes that can be returned by both
328 .\"O .BR regcomp ()
329 .\"O and
330 .\"O .BR regexec ()
331 .\"O into error message strings.
332 .BR regerror ()
333 は、
334 .BR regcomp ()
335
336 .BR regexec ()
337 の実行によって得られるエラーコードから、エラーメッセージ文字列を
338 得るのに用いられる。
339
340 .\"O .BR regerror ()
341 .\"O is passed the error code,
342 .\"O .IR errcode ,
343 .\"O the pattern buffer,
344 .\"O .IR preg ,
345 .\"O a pointer to a character string buffer,
346 .\"O .IR errbuf ,
347 .\"O and the size of the string buffer,
348 .\"O .IR errbuf_size .
349 .BR regerror ()
350 はエラーコード
351 .IR errcode 、
352 パターンバッファ
353 .IR preg 、
354 文字列バッファへのポインタ
355 .IR errbuf 、
356 文字列バッファのサイズ
357 .I errbuf_size
358 を引数にとる。
359 .\"O It returns the size of the
360 .\"O .I errbuf
361 .\"O required to contain the null-terminated error message string.
362 .\"O If both
363 .\"O .I errbuf
364 .\"O and
365 .\"O .I errbuf_size
366 .\"O are nonzero,
367 .\"O .I errbuf
368 .\"O is filled in with the first
369 .\"O .I "errbuf_size \- 1"
370 .\"O characters of the error message and a terminating null byte (\(aq\\0\(aq).
371 この関数は、ヌル文字で終端されたエラーメッセージ文字列を格納するのに必要な
372 .I errbuf
373 のサイズを返す。もし
374 .I errbuf
375
376 .I errbuf_size
377 の両方が非 0 値であれば、
378 .I errbuf
379 には最初の
380 .I "errbuf_size \- 1"
381 文字分にエラーメッセージと終端の NULL バイト (\(aq\\0\(aq)
382 が収まるように代入される。
383 .\"O .SS "POSIX Pattern Buffer Freeing"
384 .SS "POSIX パターンバッファ解放"
385 .\"O Supplying
386 .\"O .BR regfree ()
387 .\"O with a precompiled pattern buffer,
388 .\"O .I preg
389 .\"O will free the memory allocated to the pattern buffer by the compiling
390 .\"O process,
391 .\"O .BR regcomp ().
392 引数にコンパイルされたパターンバッファ
393 .I preg
394 を与えて
395 .BR regfree ()
396 を呼び出すと、
397 .BR regcomp ()
398 によるコンパイル時にパターンバッファに割り当てられたメモリが解放される。
399 .\"O .SH "RETURN VALUE"
400 .SH 返り値
401 .\"O .BR regcomp ()
402 .\"O returns zero for a successful compilation or an error code for failure.
403 .BR regcomp ()
404 は、コンパイルの成功時には 0 を返し、失敗時にはエラーコードを返す。
405
406 .\"O .BR regexec ()
407 .\"O returns zero for a successful match or
408 .\"O .B REG_NOMATCH
409 .\"O for failure.
410 .BR regexec ()
411 は、マッチングの成功時には 0 を返し、失敗時には
412 .B REG_NOMATCH
413 を返す。
414 .\"O .SH ERRORS
415 .SH エラー
416 .\"O The following errors can be returned by
417 .\"O .BR regcomp ():
418 .BR regcomp ()
419 は以下のエラーを返す。
420 .TP
421 .B REG_BADBR
422 .\"O Invalid use of back reference operator.
423 無効な後方参照オペレータの使用。
424 .TP
425 .B REG_BADPAT
426 .\"O Invalid use of pattern operators such as group or list.
427 グループやリストなどの、パターンオペレータの無効な使用。
428 .TP
429 .B REG_BADRPT
430 .\"O Invalid use of repetition operators such as using \(aq*\(aq
431 .\"O as the first character.
432 \(aq*\(aq が最初の文字としてくるような、無効な繰り返しオペレータの使用。
433 .TP
434 .B REG_EBRACE
435 .\"O Un-matched brace interval operators.
436 インターバルオペレータ
437 .B {}
438 (brace interval operators) が閉じていない。
439 .TP
440 .B REG_EBRACK
441 .\"O Un-matched bracket list operators.
442 リストオペレータ
443 .B []
444 (bracket list operators) が閉じていない。
445 .TP
446 .B REG_ECOLLATE
447 .\"O Invalid collating element.
448 照合順序の要素 (collating element) として有効ではない。
449
450 (訳注) 照合順序の要素 (collating element) については、
451 .BR regex (7)
452 を参照。
453 .TP
454 .B REG_ECTYPE
455 .\"O Unknown character class name.
456 未知のキャラクタクラス名。
457 .TP
458 .B REG_EEND
459 .\"O Non specific error.
460 .\"O This is not defined by POSIX.2.
461 未定義エラー。これは POSIX.2 には定義されていない。
462 .TP
463 .B REG_EESCAPE
464 .\"O Trailing backslash.
465 正規表現がバックスラッシュで終っている。
466
467 (訳注) 日本語環境の場合、バックスラッシュとなるべき所が円記号で
468 表示されることがあるが、これは単に表示フォントの問題で、
469 内部的には同じ意味である。
470 .TP
471 .B REG_EPAREN
472 .\"O Un-matched parenthesis group operators.
473 グループオペレータ
474 .B ()
475 (parenthesis group operators) が閉じていない。
476 .TP
477 .B REG_ERANGE
478 .\"O Invalid use of the range operator, e.g., the ending point of the range
479 .\"O occurs prior to the starting point.
480 無効な範囲オペレータの使用。
481 例えば、範囲の終了位置が開始位置よりも前にあるような場合。
482 .TP
483 .B REG_ESIZE
484 .\"O Compiled regular expression requires a pattern buffer larger than 64Kb.
485 .\"O This is not defined by POSIX.2.
486 正規表現のコンパイルに、64Kb 以上のパターンバッファが必要。
487 これは POSIX.2 には定義されていない。
488 .TP
489 .B REG_ESPACE
490 .\"O The regex routines ran out of memory.
491 regex ルーチンがメモリを使いはたしている。
492 .TP
493 .B REG_ESUBREG
494 .\"O Invalid back reference to a subexpression.
495 サブエクスプレッション
496 .RB \e (...\e )
497 (subexpression) への無効な後方参照。
498 .\"O .SH "CONFORMING TO"
499 .SH 準拠
500 POSIX.1-2001.
501 .\"O .SH "SEE ALSO"
502 .SH 関連項目
503 .BR grep (1),
504 .BR regex (7),
505 .\"O GNU regex manual
506 GNU regex マニュアル