OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man3 / regex.3
1 .de  xx
2 .in \\n(INu+\\$1
3 .ti -\\$1
4 ..
5 .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.)
6 .\"
7 .\" %%%LICENSE_START(VERBATIM)
8 .\" Permission is granted to make and distribute verbatim copies of this
9 .\" manual provided the copyright notice and this permission notice are
10 .\" preserved on all copies.
11 .\"
12 .\" Permission is granted to copy and distribute modified versions of this
13 .\" manual under the conditions for verbatim copying, provided that the
14 .\" entire resulting derived work is distributed under the terms of a
15 .\" permission notice identical to this one.
16 .\"
17 .\" Since the Linux kernel and libraries are constantly changing, this
18 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
19 .\" responsibility for errors or omissions, or for damages resulting from
20 .\" the use of the information contained herein.  The author(s) may not
21 .\" have taken the same level of care in the production of this manual,
22 .\" which is licensed free of charge, as they might when working
23 .\" professionally.
24 .\"
25 .\" Formatted or processed versions of this manual, if unaccompanied by
26 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" %%%LICENSE_END
28 .\"
29 .\" Wed Jun 14 16:10:28 BST 1995 Wilf. (G.Wilford@ee.surrey.ac.uk)
30 .\" Tiny change in formatting - aeb, 950812
31 .\" Modified 8 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
32 .\"
33 .\" show the synopsis section nicely
34 .\"*******************************************************************
35 .\"
36 .\" This file was generated with po4a. Translate the source file.
37 .\"
38 .\"*******************************************************************
39 .TH REGEX 3 2013\-02\-11 GNU "Linux Programmer's Manual"
40 .SH 名前
41 regcomp, regexec, regerror, regfree \- POSIX regex 関数
42 .SH 書式
43 .nf
44 \fB#include <sys/types.h>\fP
45 \fB#include <regex.h>\fP
46
47 \fBint regcomp(regex_t *\fP\fIpreg\fP\fB, const char *\fP\fIregex\fP\fB, int \fP\fIcflags\fP\fB);\fP
48
49 \fBint regexec(const regex_t *\fP\fIpreg\fP\fB, const char *\fP\fIstring\fP\fB, size_t \fP\fInmatch\fP\fB,\fP
50 \fB            regmatch_t \fP\fIpmatch[]\fP\fB, int \fP\fIeflags\fP\fB);\fP
51
52 \fBsize_t regerror(int \fP\fIerrcode\fP\fB, const regex_t *\fP\fIpreg\fP\fB, char *\fP\fIerrbuf\fP\fB,\fP
53 \fB                size_t \fP\fIerrbuf_size\fP\fB);\fP
54
55 \fBvoid regfree(regex_t *\fP\fIpreg\fP\fB);\fP
56 .fi
57 .SH 説明
58 .SS "POSIX regex compiling"
59 \fBregcomp\fP()  は、正規表現をコンパイルして、 \fBregexec\fP()  での検索処理に適合する形態にする。
60
61 \fBregcomp\fP()  はパターンを記憶するバッファへのポインタ \fIpreg\fP、 ヌル文字で終端された文字列 \fIregex\fP、
62 そしてコンパイルの形式を決めるためのフラグ \fIcflag\fP を引数に伴う。
63
64 全ての正規表現検索は、コンパイルされたパターンによって行わなければならない。 よって、 \fBregexec\fP()  に指定するのは、必ず
65 (\fBregcomp\fP()  によってコンパイルされた) パターンバッファへのアドレスでなければならない。
66
67 \fIcflags\fP には以下に示す定数一つ以上のビットごとの OR (bitwise\-or) を指定する。
68 .TP 
69 \fBREG_EXTENDED\fP
70 \fIregex\fP に \fBPOSIX\fP 拡張正規表現を使用する。もしこのフラグが設定されない場合、 \fBPOSIX\fP 標準正規表現が使われる。
71 .TP 
72 \fBREG_ICASE\fP
73 大文字小文字の違いを無視する。このフラグを指定してコンパイルされた パターンバッファを用いて \fBregexec\fP()
74 関数を呼び出すと、大文字小文字の区別を付けずに検索が行われる。
75 .TP 
76 \fBREG_NOSUB\fP
77 Do not report position of matches.  The \fInmatch\fP and \fIpmatch\fP arguments to
78 \fBregexec\fP()  are ignored if the pattern buffer supplied was compiled with
79 this flag set.
80 .TP 
81 \fBREG_NEWLINE\fP
82 全ての文字にマッチするオペレータに改行をマッチさせない。
83
84 改行を含まない非マッチング文字リスト (\fB[^...]\fP)  に改行をマッチさせない。
85
86 \fBregexec\fP()  の実行時に指定するフラグ \fIeflags\fP に \fBREG_NOTBOL\fP
87 を含むかどうかにかかわらず、行頭にマッチするオペレータ (\fB^\fP)  を改行直後の空文字列にマッチさせる。
88
89 \fIeflags\fP に \fBREG_NOTEOL\fP を含むかどうかにかかわらず、行末にマッチするオペレータ (\fB$\fP)
90 を改行直前の空文字列にマッチさせる。
91 .SS "POSIX regex matching"
92 \fBregexec\fP()  は、 プリコンパイルされたパターンバッファ \fIpreg\fP をヌル文字で終端された文字列にマッチさせる。 \fInmatch\fP
93 と \fIpmatch\fP はマッチングの位置に関する情報を取得するのに用いられる。 \fIeflags\fP には \fBREG_NOTBOL\fP と
94 \fBREG_NOTEOL\fP のどちらか、もしくは両方のビットごとの \fBOR\fP (bitwise\-\fBor\fP)
95 を指定し、以下で説明するようにマッチング動作を変化させる。
96 .TP 
97 \fBREG_NOTBOL\fP
98 行頭にマッチするオペレータは、必ずマッチに失敗する (コンパイル時のフラグ \fBREG_NEWLINE\fP の項目も参照)。
99 このフラグは、複数行にまたがる文字列を \fBregexec\fP()  で検索する際に、文字列の先頭を行の先頭として解釈させない場合に用いる。
100 .TP 
101 \fBREG_NOTEOL\fP
102 行末にマッチするオペレータは、必ずマッチに失敗する (コンパイル時のフラグ \fBREG_NEWLINE\fP の項目も参照)。
103 .SS "Byte offsets"
104 Unless \fBREG_NOSUB\fP was set for the compilation of the pattern buffer, it is
105 possible to obtain match addressing information.  \fIpmatch\fP must be
106 dimensioned to have at least \fInmatch\fP elements.  These are filled in by
107 \fBregexec\fP()  with substring match addresses.  The offsets of the
108 subexpression starting at the \fIi\fPth open parenthesis are stored in
109 \fIpmatch[i]\fP.  The entire regular expression's match addresses are stored in
110 \fIpmatch[0]\fP.  (Note that to return the offsets of \fIN\fP subexpression
111 matches, \fInmatch\fP must be at least \fIN+1\fP.)  Any unused structure elements
112 will contain the value \-1.
113
114 \fIpmatch\fP の型である \fIregmatch_t\fP 構造体は、 \fI<regex.h>\fP 内で定義される。
115
116 .in +4n
117 .nf
118 typedef struct {
119     regoff_t rm_so;
120     regoff_t rm_eo;
121 } regmatch_t;
122 .fi
123 .in
124
125 構造体要素 \fIrm_so\fP の値が \-1 でない場合、それは文字列内での次の最大のマッチング部分の開始 オフセット位置を示す。それに対し、構造体要素
126 \fIrm_eo\fP はマッチング部分の終了オフセット位置を示し、 マッチング部分の直後の文字のオフセット位置が使用される。
127 .SS "POSIX error reporting"
128 \fBregerror\fP()  は、 \fBregcomp\fP()  と \fBregexec\fP()
129 の実行によって得られるエラーコードから、エラーメッセージ文字列を 得るのに用いられる。
130
131 \fBregerror\fP()  はエラーコード \fIerrcode\fP、 パターンバッファ \fIpreg\fP、 文字列バッファへのポインタ
132 \fIerrbuf\fP、 文字列バッファのサイズ \fIerrbuf_size\fP を引数にとる。
133 この関数は、ヌル文字で終端されたエラーメッセージ文字列を格納するのに必要な \fIerrbuf\fP のサイズを返す。もし \fIerrbuf\fP と
134 \fIerrbuf_size\fP の両方が非 0 値であれば、 \fIerrbuf\fP には最初の \fIerrbuf_size \- 1\fP
135 文字分にエラーメッセージと終端の NULL バイト (\(aq\e0\(aq)  が収まるように代入される。
136 .SS "POSIX pattern buffer freeing"
137 引数にコンパイルされたパターンバッファ \fIpreg\fP を与えて \fBregfree\fP()  を呼び出すと、 \fBregcomp\fP()
138 によるコンパイル時にパターンバッファに割り当てられたメモリが解放される。
139 .SH 返り値
140 \fBregcomp\fP()  は、コンパイルの成功時には 0 を返し、失敗時にはエラーコードを返す。
141
142 \fBregexec\fP()  は、マッチングの成功時には 0 を返し、失敗時には \fBREG_NOMATCH\fP を返す。
143 .SH エラー
144 \fBregcomp\fP()  は以下のエラーを返す。
145 .TP 
146 \fBREG_BADBR\fP
147 無効な後方参照オペレータの使用。
148 .TP 
149 \fBREG_BADPAT\fP
150 グループやリストなどの、パターンオペレータの無効な使用。
151 .TP 
152 \fBREG_BADRPT\fP
153 \(aq*\(aq が最初の文字としてくるような、無効な繰り返しオペレータの使用。
154 .TP 
155 \fBREG_EBRACE\fP
156 インターバルオペレータ \fB{}\fP (brace interval operators) が閉じていない。
157 .TP 
158 \fBREG_EBRACK\fP
159 リストオペレータ \fB[]\fP (bracket list operators) が閉じていない。
160 .TP 
161 \fBREG_ECOLLATE\fP
162 照合順序の要素 (collating element) として有効ではない。 (訳注) 詳細は \fBregex\fP(7)  を参照。
163 .TP 
164 \fBREG_ECTYPE\fP
165 未知のキャラクタクラス名。
166 .TP 
167 \fBREG_EEND\fP
168 Nonspecific error.  This is not defined by POSIX.2.
169 .TP 
170 \fBREG_EESCAPE\fP
171 正規表現がバックスラッシュで終っている。
172 .TP 
173 \fBREG_EPAREN\fP
174 グループオペレータ \fB()\fP (parenthesis group operators) が閉じていない。
175 .TP 
176 \fBREG_ERANGE\fP
177 無効な範囲オペレータの使用。 例えば、範囲の終了位置が開始位置よりも前にあるような場合。
178 .TP 
179 \fBREG_ESIZE\fP
180 正規表現のコンパイルに、64Kb 以上のパターンバッファが必要。 これは POSIX.2 には定義されていない。
181 .TP 
182 \fBREG_ESPACE\fP
183 regex ルーチンがメモリを使いはたしている。
184 .TP 
185 \fBREG_ESUBREG\fP
186 サブエクスプレッション \e\fB(...\e\fP)  (subexpression) への無効な後方参照。
187 .SH 準拠
188 POSIX.1\-2001.
189 .SH 関連項目
190 \fBgrep\fP(1), \fBregex\fP(7)
191 .br
192 The glibc manual section, \fIRegular Expression Matching\fP
193 .SH この文書について
194 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
195 である。プロジェクトの説明とバグ報告に関する情報は
196 http://www.kernel.org/doc/man\-pages/ に書かれている。