1 .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
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)
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
34 .\"WORD: bitwise-or ¥Ó¥Ã¥È¤´¤È¤ÎOR
35 .\"WORD: element (¹½Â¤ÂÎ)Í×ÁÇ
36 .\"WORD: collating element ¾È¹ç½ç½ø¤ÎÍ×ÁÇ
38 .\" show the synopsis section nicely
43 .TH REGEX 3 2008-05-29 "GNU" "Linux Programmer's Manual"
46 .\"O regcomp, regexec, regerror, regfree \- POSIX regex functions
47 regcomp, regexec, regerror, regfree \- POSIX regex ´Ø¿ô
51 .B #include <sys/types.h>
54 .BI "int regcomp(regex_t *" preg ", const char *" regex ", int " cflags );
56 .BI "int regexec(const regex_t *" preg ", const char *" string \
58 .BI " regmatch_t " pmatch[] ", int " eflags );
60 .BI "size_t regerror(int " errcode ", const regex_t *" preg ", char *" errbuf ,
61 .BI " size_t " errbuf_size );
63 .BI "void regfree(regex_t *" preg );
67 .\"O .SS "POSIX Regex Compiling"
68 .SS "POSIX regex ¥³¥ó¥Ñ¥¤¥ë"
70 .\"O is used to compile a regular expression into a form that is suitable
75 ¤Ï¡¢Àµµ¬É½¸½¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Æ¡¢
77 ¤Ç¤Î¸¡º÷½èÍý¤ËŬ¹ç¤¹¤ë·ÁÂ֤ˤ¹¤ë¡£
82 .\"O a pointer to a pattern buffer storage area;
84 .\"O a pointer to the null-terminated string and
86 .\"O flags used to determine the type of compilation.
88 ¤Ï¥Ñ¥¿¡¼¥ó¤òµ²±¤¹¤ë¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ý¥¤¥ó¥¿
90 ¥Ì¥ëʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó
92 ¤½¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤Î·Á¼°¤ò·è¤á¤ë¤¿¤á¤Î¥Õ¥é¥°
96 .\"O All regular expression searching must be done via a compiled pattern
99 .\"O must always be supplied with the address of a
101 .\"O initialized pattern buffer.
102 Á´¤Æ¤ÎÀµµ¬É½¸½¸¡º÷¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¥Ñ¥¿¡¼¥ó¤Ë¤è¤Ã¤Æ¹Ô¤ï¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
107 ¤Ë¤è¤Ã¤Æ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿) ¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥¢¥É¥ì¥¹¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
112 .\"O of one or more of the following:
114 ¤Ë¤Ï°Ê²¼¤Ë¼¨¤¹Äê¿ô°ì¤Ä°Ê¾å¤Î¥Ó¥Ã¥È¤´¤È¤Î OR (bitwise-or) ¤ò»ØÄꤹ¤ë¡£
119 .\"O Extended Regular Expression syntax when interpreting
123 .\"O Basic Regular Expression syntax is used.
127 ³ÈÄ¥Àµµ¬É½¸½¤ò»ÈÍѤ¹¤ë¡£¤â¤·¤³¤Î¥Õ¥é¥°¤¬ÀßÄꤵ¤ì¤Ê¤¤¾ì¹ç¡¢
129 ɸ½àÀµµ¬É½¸½¤¬»È¤ï¤ì¤ë¡£
132 .\"O Do not differentiate case.
135 .\"O searches using this pattern buffer will be case insensitive.
136 Âçʸ»ú¾®Ê¸»ú¤Î°ã¤¤¤ò̵»ë¤¹¤ë¡£¤³¤Î¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿
137 ¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤òÍѤ¤¤Æ
139 ´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹¤È¡¢Âçʸ»ú¾®Ê¸»ú¤Î¶èÊ̤òÉÕ¤±¤º¤Ë¸¡º÷¤¬¹Ô¤ï¤ì¤ë¡£
142 .\"O Support for substring addressing of matches is not required.
149 .\"O are ignored if the pattern buffer supplied was compiled with this flag set.
150 ¤³¤Î¥Õ¥é¥°¤òÀßÄꤷ¤Æ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤¬
152 ¤Î°ú¿ô¤Ë»ØÄꤵ¤ì¤ë¤È¡¢°ú¤¿ô
158 .\"O Match-any-character operators don't match a newline.
159 Á´¤Æ¤Îʸ»ú¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ª¥Ú¥ì¡¼¥¿¤Ë²þ¹Ô¤ò¥Þ¥Ã¥Á¤µ¤»¤Ê¤¤¡£
161 .\"O A nonmatching list
163 .\"O not containing a newline does not match a newline.
164 ²þ¹Ô¤ò´Þ¤Þ¤Ê¤¤Èó¥Þ¥Ã¥Á¥ó¥°Ê¸»ú¥ê¥¹¥È
166 ¤Ë²þ¹Ô¤ò¥Þ¥Ã¥Á¤µ¤»¤Ê¤¤¡£
168 .\"O Match-beginning-of-line operator
170 .\"O matches the empty string immediately after a newline, regardless of
173 .\"O the execution flags of
176 .\"O .BR REG_NOTBOL .
178 ¤Î¼Â¹Ô»þ¤Ë»ØÄꤹ¤ë¥Õ¥é¥°
182 ¤ò´Þ¤à¤«¤É¤¦¤«¤Ë¤«¤«¤ï¤é¤º¡¢¹ÔƬ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ª¥Ú¥ì¡¼¥¿
184 ¤ò²þ¹Ôľ¸å¤Î¶õʸ»úÎó¤Ë¥Þ¥Ã¥Á¤µ¤»¤ë¡£
186 .\"O Match-end-of-line operator
188 .\"O matches the empty string immediately before a newline, regardless of
192 .\"O .BR REG_NOTEOL .
196 ¤ò´Þ¤à¤«¤É¤¦¤«¤Ë¤«¤«¤ï¤é¤º¡¢¹ÔËö¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ª¥Ú¥ì¡¼¥¿
198 ¤ò²þ¹ÔľÁ°¤Î¶õʸ»úÎó¤Ë¥Þ¥Ã¥Á¤µ¤»¤ë¡£
199 .\"O .SS "POSIX Regex Matching"
200 .SS "POSIX regex ¥Þ¥Ã¥Á¥ó¥°"
202 .\"O is used to match a null-terminated string
203 .\"O against the precompiled pattern buffer,
207 ¥×¥ê¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡
209 ¤ò¥Ì¥ëʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ë¥Þ¥Ã¥Á¤µ¤»¤ë¡£
213 .\"O are used to provide information regarding the location of any matches.
217 ¤Ï¥Þ¥Ã¥Á¥ó¥°¤Î°ÌÃ֤˴ؤ¹¤ë¾ðÊó¤ò¼èÆÀ¤¹¤ë¤Î¤ËÍѤ¤¤é¤ì¤ë¡£
221 .\"O of one or both of
225 .\"O which cause changes in matching behavior described below.
231 ¤Î¤É¤Á¤é¤«¡¢¤â¤·¤¯¤ÏξÊý¤Î¥Ó¥Ã¥È¤´¤È¤Î
232 .BR OR " (bitwise-" or )
233 ¤ò»ØÄꤷ¡¢°Ê²¼¤ÇÀâÌÀ¤¹¤ë¤è¤¦¤Ë¥Þ¥Ã¥Á¥ó¥°Æ°ºî¤òÊѲ½¤µ¤»¤ë¡£
236 .\"O The match-beginning-of-line operator always fails to match (but see the
237 .\"O compilation flag
241 ¹ÔƬ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ª¥Ú¥ì¡¼¥¿¤Ï¡¢É¬¤º¥Þ¥Ã¥Á¤Ë¼ºÇÔ¤¹¤ë (¥³¥ó¥Ñ¥¤¥ë»þ¤Î¥Õ¥é¥°
244 .\"O This flag may be used when different portions of a string are passed to
246 .\"O and the beginning of the string should not be interpreted as the
247 .\"O beginning of the line.
248 ¤³¤Î¥Õ¥é¥°¤Ï¡¢Ê£¿ô¹Ô¤Ë¤Þ¤¿¤¬¤ëʸ»úÎó¤ò
250 ¤Ç¸¡º÷¤¹¤ëºÝ¤Ë¡¢Ê¸»úÎó¤ÎÀèƬ¤ò¹Ô¤ÎÀèƬ¤È¤·¤Æ²ò¼á¤µ¤»¤Ê¤¤¾ì¹ç¤ËÍѤ¤¤ë¡£
253 .\"O The match-end-of-line operator always fails to match (but see the
254 .\"O compilation flag
258 ¹ÔËö¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ª¥Ú¥ì¡¼¥¿¤Ï¡¢É¬¤º¥Þ¥Ã¥Á¤Ë¼ºÇÔ¤¹¤ë (¥³¥ó¥Ñ¥¤¥ë»þ¤Î¥Õ¥é¥°
261 .\"O .SS "Byte Offsets"
265 .\"O was set for the compilation of the pattern buffer, it is possible to
266 .\"O obtain substring match addressing information.
267 ¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤Î¥³¥ó¥Ñ¥¤¥ë»þ¤Ë
269 ¤¬ÀßÄꤵ¤ì¤Ê¤¤¾ì¹ç¤Ï¡¢Éôʬʸ»úÎó¤Î¥Þ¥Ã¥Á¥ó¥°°ÌÃÖ¾ðÊó¤òÆÀ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
271 .\"O must be dimensioned to have at least
277 ¤ÎÂ礤µ¤ò»ý¤Ä¤è¤¦¤Ë»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
278 .\"O These are filled in by
280 .\"O with substring match addresses.
281 .\"O Any unused structure elements
282 .\"O will contain the value \-1.
284 ¤Î¼Â¹Ô¤Ë¤è¤Ã¤Æ¡¢¤½¤ì¤é¤ËÉôʬʸ»úÎó¥Þ¥Ã¥Á¥ó¥°°ÌÃÖ¾ðÊó¤¬ÂåÆþ¤µ¤ì¤ë¡£
285 ̤»ÈÍѤι½Â¤ÂÎÍ×ÁÇ¤Ë¤Ï \-1 ¤¬ÃͤȤ·¤ÆÂåÆþ¤µ¤ì¤ë¡£
289 .\"O structure which is the type of
311 .\"O element that is not \-1 indicates the start offset of the next largest
312 .\"O substring match within the string.
315 .\"O element indicates the end offset of the match,
316 .\"O which is the offset of the first character after the matching text.
319 ¤ÎÃͤ¬ \-1 ¤Ç¤Ê¤¤¾ì¹ç¡¢¤½¤ì¤Ïʸ»úÎóÆâ¤Ç¤Î¼¡¤ÎºÇÂç¤Î¥Þ¥Ã¥Á¥ó¥°Éôʬ¤Î³«»Ï
320 ¥ª¥Õ¥»¥Ã¥È°ÌÃÖ¤ò¼¨¤¹¡£¤½¤ì¤ËÂФ·¡¢¹½Â¤ÂÎÍ×ÁÇ
322 ¤Ï¥Þ¥Ã¥Á¥ó¥°Éôʬ¤Î½ªÎ»¥ª¥Õ¥»¥Ã¥È°ÌÃÖ¤ò¼¨¤·¡¢
323 ¥Þ¥Ã¥Á¥ó¥°Éôʬ¤Îľ¸å¤Îʸ»ú¤Î¥ª¥Õ¥»¥Ã¥È°ÌÃÖ¤¬»ÈÍѤµ¤ì¤ë¡£
324 .\"O .SH "POSIX Error Reporting"
325 .SS "POSIX ¥¨¥é¡¼¥ì¥Ý¡¼¥È"
327 .\"O is used to turn the error codes that can be returned by both
331 .\"O into error message strings.
337 ¤Î¼Â¹Ô¤Ë¤è¤Ã¤ÆÆÀ¤é¤ì¤ë¥¨¥é¡¼¥³¡¼¥É¤«¤é¡¢¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸Ê¸»úÎó¤ò
341 .\"O is passed the error code,
343 .\"O the pattern buffer,
345 .\"O a pointer to a character string buffer,
347 .\"O and the size of the string buffer,
348 .\"O .IR errbuf_size .
354 ʸ»úÎó¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ý¥¤¥ó¥¿
356 ʸ»úÎó¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º
359 .\"O It returns the size of the
361 .\"O required to contain the null-terminated error message string.
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.
371 ¤³¤Î´Ø¿ô¤Ï¡¢¥Ì¥ëʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸Ê¸»úÎó¤ò³ÊǼ¤¹¤ë¤Î¤ËɬÍפÊ
377 ¤ÎξÊý¤¬Èó 0 ÃͤǤ¢¤ì¤Ð¡¢
380 .I "errbuf_size \- 1"
381 ʸ»úʬ¤Ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤È½ªÃ¼¤Î¥Ì¥ëʸ»ú¤¬¼ý¤Þ¤ë¤è¤¦¤ËÂåÆþ¤µ¤ì¤ë¡£
382 .\"O .SS "POSIX Pattern Buffer Freeing"
383 .SS "POSIX ¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡²òÊü"
386 .\"O with a precompiled pattern buffer,
388 .\"O will free the memory allocated to the pattern buffer by the compiling
391 °ú¿ô¤Ë¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡
397 ¤Ë¤è¤ë¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤¬²òÊü¤µ¤ì¤ë¡£
398 .\"O .SH "RETURN VALUE"
401 .\"O returns zero for a successful compilation or an error code for failure.
403 ¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë¤ÎÀ®¸ù»þ¤Ë¤Ï 0 ¤òÊÖ¤·¡¢¼ºÇÔ»þ¤Ë¤Ï¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹¡£
406 .\"O returns zero for a successful match or
410 ¤Ï¡¢¥Þ¥Ã¥Á¥ó¥°¤ÎÀ®¸ù»þ¤Ë¤Ï 0 ¤òÊÖ¤·¡¢¼ºÇÔ»þ¤Ë¤Ï
415 .\"O The following errors can be returned by
418 ¤Ï°Ê²¼¤Î¥¨¥é¡¼¤òÊÖ¤¹¡£
421 .\"O Invalid use of back reference operator.
422 ̵¸ú¤Ê¸åÊý»²¾È¥ª¥Ú¥ì¡¼¥¿¤Î»ÈÍÑ¡£
425 .\"O Invalid use of pattern operators such as group or list.
426 ¥°¥ë¡¼¥×¤ä¥ê¥¹¥È¤Ê¤É¤Î¡¢¥Ñ¥¿¡¼¥ó¥ª¥Ú¥ì¡¼¥¿¤Î̵¸ú¤Ê»ÈÍÑ¡£
429 .\"O Invalid use of repetition operators such as using \(aq*\(aq
430 .\"O as the first character.
431 \(aq*\(aq ¤¬ºÇ½é¤Îʸ»ú¤È¤·¤Æ¤¯¤ë¤è¤¦¤Ê¡¢Ìµ¸ú¤Ê·«¤êÊÖ¤·¥ª¥Ú¥ì¡¼¥¿¤Î»ÈÍÑ¡£
434 .\"O Un-matched brace interval operators.
435 ¥¤¥ó¥¿¡¼¥Ð¥ë¥ª¥Ú¥ì¡¼¥¿
437 (brace interval operators) ¤¬ÊĤ¸¤Æ¤¤¤Ê¤¤¡£
440 .\"O Un-matched bracket list operators.
443 (bracket list operators) ¤¬ÊĤ¸¤Æ¤¤¤Ê¤¤¡£
446 .\"O Invalid collating element.
447 ¾È¹ç½ç½ø¤ÎÍ×ÁÇ (collating element) ¤È¤·¤Æ͸ú¤Ç¤Ï¤Ê¤¤¡£
449 (ÌõÃí) ¾È¹ç½ç½ø¤ÎÍ×ÁÇ (collating element) ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
454 .\"O Unknown character class name.
455 ̤ÃΤΥ¥ã¥é¥¯¥¿¥¯¥é¥¹Ì¾¡£
458 .\"O Non specific error.
459 .\"O This is not defined by POSIX.2.
460 ̤ÄêµÁ¥¨¥é¡¼¡£¤³¤ì¤Ï POSIX.2 ¤Ë¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
463 .\"O Trailing backslash.
464 Àµµ¬É½¸½¤¬¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤Ç½ª¤Ã¤Æ¤¤¤ë¡£
466 (ÌõÃí) ÆüËܸì´Ä¶¤Î¾ì¹ç¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤È¤Ê¤ë¤Ù¤½ê¤¬±ßµ¹æ¤Ç
467 ɽ¼¨¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¤¬¡¢¤³¤ì¤Ïñ¤Ëɽ¼¨¥Õ¥©¥ó¥È¤ÎÌäÂê¤Ç¡¢
468 ÆâÉôŪ¤Ë¤ÏƱ¤¸°ÕÌ£¤Ç¤¢¤ë¡£
471 .\"O Un-matched parenthesis group operators.
474 (parenthesis group operators) ¤¬ÊĤ¸¤Æ¤¤¤Ê¤¤¡£
477 .\"O Invalid use of the range operator, e.g., the ending point of the range
478 .\"O occurs prior to the starting point.
479 ̵¸ú¤ÊÈÏ°Ï¥ª¥Ú¥ì¡¼¥¿¤Î»ÈÍÑ¡£
480 Î㤨¤Ð¡¢ÈϰϤνªÎ»°ÌÃÖ¤¬³«»Ï°ÌÃÖ¤è¤ê¤âÁ°¤Ë¤¢¤ë¤è¤¦¤Ê¾ì¹ç¡£
483 .\"O Compiled regular expression requires a pattern buffer larger than 64Kb.
484 .\"O This is not defined by POSIX.2.
485 Àµµ¬É½¸½¤Î¥³¥ó¥Ñ¥¤¥ë¤Ë¡¢64Kb °Ê¾å¤Î¥Ñ¥¿¡¼¥ó¥Ð¥Ã¥Õ¥¡¤¬É¬Íס£
486 ¤³¤ì¤Ï POSIX.2 ¤Ë¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
489 .\"O The regex routines ran out of memory.
490 regex ¥ë¡¼¥Á¥ó¤¬¥á¥â¥ê¤ò»È¤¤¤Ï¤¿¤·¤Æ¤¤¤ë¡£
493 .\"O Invalid back reference to a subexpression.
494 ¥µ¥Ö¥¨¥¯¥¹¥×¥ì¥Ã¥·¥ç¥ó
496 (subexpression) ¤Ø¤Î̵¸ú¤Ê¸åÊý»²¾È¡£
497 .\"O .SH "CONFORMING TO"
504 .\"O GNU regex manual