1 .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Wed Jun 14 16:10:28 BST 1995 Wilf. (G.Wilford@ee.surrey.ac.uk)
26 .\" Tiny change in formatting - aeb, 950812
27 .\" Modified 8 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
29 .\" show the synopsis section nicely
34 .TH REGEX 3 2013-02-11 "GNU" "Linux Programmer's Manual"
36 regcomp, regexec, regerror, regfree \- POSIX regex functions
39 .B #include <sys/types.h>
42 .BI "int regcomp(regex_t *" preg ", const char *" regex ", int " cflags );
44 .BI "int regexec(const regex_t *" preg ", const char *" string \
46 .BI " regmatch_t " pmatch[] ", int " eflags );
48 .BI "size_t regerror(int " errcode ", const regex_t *" preg ", char *" errbuf ,
49 .BI " size_t " errbuf_size );
51 .BI "void regfree(regex_t *" preg );
54 .SS POSIX regex compiling
56 is used to compile a regular expression into a form that is suitable
64 a pointer to a pattern buffer storage area;
66 a pointer to the null-terminated string and
68 flags used to determine the type of compilation.
70 All regular expression searching must be done via a compiled pattern
73 must always be supplied with the address of a
75 initialized pattern buffer.
80 of one or more of the following:
85 Extended Regular Expression syntax when interpreting
89 Basic Regular Expression syntax is used.
92 Do not differentiate case.
95 searches using this pattern buffer will be case insensitive.
98 Do not report position of matches.
105 are ignored if the pattern buffer supplied was compiled with this flag set.
108 Match-any-character operators don't match a newline.
112 not containing a newline does not match a newline.
114 Match-beginning-of-line operator
116 matches the empty string immediately after a newline, regardless of
119 the execution flags of
124 Match-end-of-line operator
126 matches the empty string immediately before a newline, regardless of
131 .SS POSIX regex matching
133 is used to match a null-terminated string
134 against the precompiled pattern buffer,
139 are used to provide information regarding the location of any matches.
147 which cause changes in matching behavior described below.
150 The match-beginning-of-line operator always fails to match (but see the
154 This flag may be used when different portions of a string are passed to
156 and the beginning of the string should not be interpreted as the
157 beginning of the line.
160 The match-end-of-line operator always fails to match (but see the
167 was set for the compilation of the pattern buffer, it is possible to
168 obtain match addressing information.
170 must be dimensioned to have at least
173 These are filled in by
175 with substring match addresses.
176 The offsets of the subexpression starting at the
178 open parenthesis are stored in
180 The entire regular expression's match addresses are stored in
182 (Note that to return the offsets of
184 subexpression matches,
188 Any unused structure elements will contain the value \-1.
192 structure which is the type of
208 element that is not \-1 indicates the start offset of the next largest
209 substring match within the string.
212 element indicates the end offset of the match,
213 which is the offset of the first character after the matching text.
214 .SS POSIX error reporting
216 is used to turn the error codes that can be returned by both
220 into error message strings.
223 is passed the error code,
227 a pointer to a character string buffer,
229 and the size of the string buffer,
231 It returns the size of the
233 required to contain the null-terminated error message string.
240 is filled in with the first
241 .I "errbuf_size \- 1"
242 characters of the error message and a terminating null byte (\(aq\\0\(aq).
243 .SS POSIX pattern buffer freeing
246 with a precompiled pattern buffer,
248 will free the memory allocated to the pattern buffer by the compiling
253 returns zero for a successful compilation or an error code for failure.
256 returns zero for a successful match or
260 The following errors can be returned by
264 Invalid use of back reference operator.
267 Invalid use of pattern operators such as group or list.
270 Invalid use of repetition operators such as using \(aq*\(aq
271 as the first character.
274 Un-matched brace interval operators.
277 Un-matched bracket list operators.
280 Invalid collating element.
283 Unknown character class name.
287 This is not defined by POSIX.2.
293 Un-matched parenthesis group operators.
296 Invalid use of the range operator, e.g., the ending point of the range
297 occurs prior to the starting point.
300 Compiled regular expression requires a pattern buffer larger than 64Kb.
301 This is not defined by POSIX.2.
304 The regex routines ran out of memory.
307 Invalid back reference to a subexpression.
314 The glibc manual section,
315 .I "Regular Expression Matching"