V10/man/adm/man3/regexp.3

Compare this file to the similar file:
Show the results in this format:

.TH REGEXP 3
.CT 2 data_man
.SH NAME
regcomp, regexec, regsub, regerror \(mi regular expression
.SH SYNOPSIS
.nf
.B #include <regexp.h>
.PP
.B regexp *regcomp(exp)
.B char *exp;
.PP
.B int regexec(prog, string, match, msize)
.B regexp *prog;
.B char *string;
.B regsubexp *match;
.B int msize;
.PP
.B void regsub(source, dest, match, msize)
.B char *source, *dest;
.B regsubexp *match;
.B int msize;
.PP
.B void regerror(msg)
.B char *msg;
.fi
.SH DESCRIPTION
.I Regcomp
compiles a
regular expression and returns
a pointer to a compiled regular expression.
The space is allocated by
.IR malloc (3)
and may be released by
.I free.
Regular expressions are as in
.IR re (3)
except that newlines are not operators and back-references (with
\fB\e\fIn\fR) are not supported.
.PP
.I Regexec
matches a null-terminated
.I string
against the compiled regular expression in
.I prog.
If it matches,
.I regexec
returns a non-zero value and fills in the array
.I match
with character pointers to the substrings of
.I string
that correspond to the
parenthesized subexpressions of 
.IR exp :
.BI match[ i ].sp
points to the beginning and
.BI match[ i ].ep
points just beyond
the end of the
.IR i th
substring.
(Subexpression
.I i
begins at the
.IR i th
left parenthesis, counting from 1.)
Pointers in
.B match[0]
pick out the substring that corresponds to
the whole regular expression.
Unused elements of
.I match
are filled with zeros.
Matches involving
.LR * ,
.LR + ,
and 
.L ?
are extended as far as possible.
The number of array elements in 
.I match
is given by
.I msize.
The structure of elements of
.I match 
is:
.IP
.EX
typedef struct {
	char *sp;
	char *ep;
} regsubexp;
.EE
.LP
.I Regsub
places in
.I dest
a substitution instance of
.I source
in the context of the last
.I regexec
performed using
.I match.
Each instance of
.BI \e n ,
where
.I n
is a digit, is replaced by the
string delimited by
.BI match[ n ].sp
and
.BI match[ n ].ep .
Each instance of 
.L &
is replaced by the string delimited by
.B match[0].sp
and
.BR match[0].ep .
.LP
.I Regerror,
called whenever an error is detected in
.I regcomp,
.I regexec,
or
.I regsub,
writes the string
.I msg
on the standard error file and exits.
.I Regerror
can be replaced to perform
special error processing.
.SH "SEE ALSO"
.IR gre (1),
.IR re (3), 
.IR expr (1)
.SH DIAGNOSTICS
.I Regcomp
returns 
.B (regexp *)0
for an illegal expression
or other failure.
.I Regexec
returns 0
if
.I string
is not accepted.