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
30 .TH REGEX 3 2013-02-11 "GNU" "Linux Programmer's Manual"
32 regcomp, regexec, regerror, regfree \- POSIX regex functions
35 .B #include <sys/types.h>
38 .BI "int regcomp(regex_t *" preg ", const char *" regex ", int " cflags );
40 .BI "int regexec(const regex_t *" preg ", const char *" string \
42 .BI " regmatch_t " pmatch[] ", int " eflags );
44 .BI "size_t regerror(int " errcode ", const regex_t *" preg ", char *" errbuf ,
45 .BI " size_t " errbuf_size );
47 .BI "void regfree(regex_t *" preg );
50 .SS POSIX regex compiling
52 is used to compile a regular expression into a form that is suitable
60 a pointer to a pattern buffer storage area;
62 a pointer to the null-terminated string and
64 flags used to determine the type of compilation.
66 All regular expression searching must be done via a compiled pattern
69 must always be supplied with the address of a
71 initialized pattern buffer.
76 of one or more of the following:
81 Extended Regular Expression syntax when interpreting
85 Basic Regular Expression syntax is used.
88 Do not differentiate case.
91 searches using this pattern buffer will be case insensitive.
94 Do not report position of matches.
101 are ignored if the pattern buffer supplied was compiled with this flag set.
104 Match-any-character operators don't match a newline.
108 not containing a newline does not match a newline.
110 Match-beginning-of-line operator
112 matches the empty string immediately after a newline, regardless of
115 the execution flags of
120 Match-end-of-line operator
122 matches the empty string immediately before a newline, regardless of
127 .SS POSIX regex matching
129 is used to match a null-terminated string
130 against the precompiled pattern buffer,
135 are used to provide information regarding the location of any matches.
143 which cause changes in matching behavior described below.
146 The match-beginning-of-line operator always fails to match (but see the
150 This flag may be used when different portions of a string are passed to
152 and the beginning of the string should not be interpreted as the
153 beginning of the line.
156 The match-end-of-line operator always fails to match (but see the
163 was set for the compilation of the pattern buffer, it is possible to
164 obtain match addressing information.
166 must be dimensioned to have at least
169 These are filled in by
171 with substring match addresses.
172 The offsets of the subexpression starting at the
174 open parenthesis are stored in
176 The entire regular expression's match addresses are stored in
178 (Note that to return the offsets of
180 subexpression matches,
184 Any unused structure elements will contain the value \-1.
188 structure which is the type of
204 element that is not \-1 indicates the start offset of the next largest
205 substring match within the string.
208 element indicates the end offset of the match,
209 which is the offset of the first character after the matching text.
210 .SS POSIX error reporting
212 is used to turn the error codes that can be returned by both
216 into error message strings.
219 is passed the error code,
223 a pointer to a character string buffer,
225 and the size of the string buffer,
227 It returns the size of the
229 required to contain the null-terminated error message string.
236 is filled in with the first
237 .I "errbuf_size \- 1"
238 characters of the error message and a terminating null byte (\(aq\\0\(aq).
239 .SS POSIX pattern buffer freeing
242 with a precompiled pattern buffer,
244 will free the memory allocated to the pattern buffer by the compiling
249 returns zero for a successful compilation or an error code for failure.
252 returns zero for a successful match or
256 The following errors can be returned by
260 Invalid use of back reference operator.
263 Invalid use of pattern operators such as group or list.
266 Invalid use of repetition operators such as using \(aq*\(aq
267 as the first character.
270 Un-matched brace interval operators.
273 Un-matched bracket list operators.
276 Invalid collating element.
279 Unknown character class name.
283 This is not defined by POSIX.2.
289 Un-matched parenthesis group operators.
292 Invalid use of the range operator; for example, the ending point of the range
293 occurs prior to the starting point.
296 Compiled regular expression requires a pattern buffer larger than 64Kb.
297 This is not defined by POSIX.2.
300 The regex routines ran out of memory.
303 Invalid back reference to a subexpression.
310 The glibc manual section,
311 .I "Regular Expression Matching"