Manual Page Result
0
Command: regexp | Section: 3 | Source: UNIX v10 | File: regexp.3
REGEXP(3) Library Functions Manual REGEXP(3)
NAME
regcomp, regexec, regsub, regerror - regular expression
SYNOPSIS
#include <regexp.h>
regexp *regcomp(exp)
char *exp;
int regexec(prog, string, match, msize)
regexp *prog;
char *string;
regsubexp *match;
int msize;
void regsub(source, dest, match, msize)
char *source, *dest;
regsubexp *match;
int msize;
void regerror(msg)
char *msg;
DESCRIPTION
Regcomp compiles a regular expression and returns a pointer to a com-
piled regular expression. The space is allocated by malloc(3) and may
be released by free. Regular expressions are as in re(3) except that
newlines are not operators and back-references (with \n) are not sup-
ported.
Regexec matches a null-terminated string against the compiled regular
expression in prog. If it matches, regexec returns a non-zero value
and fills in the array match with character pointers to the substrings
of string that correspond to the parenthesized subexpressions of exp:
match[i].sp points to the beginning and match[i].ep points just beyond
the end of the ith substring. (Subexpression i begins at the ith left
parenthesis, counting from 1.) Pointers in match[0] pick out the sub-
string that corresponds to the whole regular expression. Unused ele-
ments of match are filled with zeros. Matches involving and are ex-
tended as far as possible. The number of array elements in match is
given by msize. The structure of elements of match is:
typedef struct {
char *sp;
char *ep;
} regsubexp;
Regsub places in dest a substitution instance of source in the context
of the last regexec performed using match. Each instance of \n, where
n is a digit, is replaced by the string delimited by match[n].sp and
match[n].ep. Each instance of is replaced by the string delimited by
match[0].sp and match[0].ep.
Regerror, called whenever an error is detected in regcomp, regexec, or
regsub, writes the string msg on the standard error file and exits.
Regerror can be replaced to perform special error processing.
SEE ALSO
gre(1), re(3), expr(1)
DIAGNOSTICS
Regcomp returns (regexp *)0 for an illegal expression or other failure.
Regexec returns 0 if string is not accepted.
REGEXP(3)