Reference

re(3)

regular expression library

NAME

recomp, reexec, ressub, refree, reerror − regular expression library

SYNOPSIS

#include <re.h>
Re_program_t* recomp(char* pattern, int flags);
int reexec(Re_program_t* re, char* source);
void ressub(Re_program_t* re, Sfio_t* sp, char* old, char* new, int flags);
void reerror(char* message);
void refree(Re_program_t* re);

DESCRIPTION

$1$2recomprecomprecomprecomprecomprecomprecomprecomp compiles a regular expression in pattern and returns a pointer to the compiled regular expression. The space is allocated by malloc(3) and may be released by $1$2refreerefreerefreerefreerefreerefreerefreerefree Regular expressions are as in egrep(1) except that newlines are treated as ordinary characters and $1$2$$$$$$$$ matches the end of a null-terminated string. flags may be $1$2RE_EDSTYLERE_EDSTYLERE_EDSTYLERE_EDSTYLERE_EDSTYLERE_EDSTYLERE_EDSTYLERE_EDSTYLE which specifies ed(1) style special characters, $1$2\(\(\(\(\(\(\(\( $1$2\)\)\)\)\)\)\)\) $1$2\?\?\?\?\?\?\?\? $1$2\+\+\+\+\+\+\+\+ and $1$2\|\|\|\|\|\|\|\| for the egrep(1) $1$2(((((((( $1$2)))))))) $1$2???????? $1$2++++++++ and $1$2|||||||| respectively.

$1$2reexecreexecreexecreexecreexecreexecreexecreexec matches the null-terminated source string against the compiled regular expression re from a previous call to $1$2recomprecomprecomprecomprecomprecomprecomprecomp If it matches, $1$2reexecreexecreexecreexecreexecreexecreexecreexec returns a non-zero value. If flags is $1$2RE_MATCHRE_MATCHRE_MATCHRE_MATCHRE_MATCHRE_MATCHRE_MATCHRE_MATCH then the array re->match is filled with character pointers to the substrings of source that correspond to the parenthesized subexpressions of pattern: re->match[i].sp points to the beginning and re->match[i].ep points just beyond the end of substring i. (Subexpression i begins at the ith matched left parenthesis, counting from 1.) Pointers in re->match[0] pick out the substring that corresponds to the entire regular expression. Unused elements of re->match are filled with zeros. Matches involving $1$2******** $1$2++++++++ and $1$2???????? are extended as far as possible. A maximum of 9 subexpressions will be matched. The structure of elements of re->match is:

	typedef struct
	{
		char* sp;
		char* ep;
	} rematch;

$1$2ressubressubressubressubressubressubressubressub places in the sfio(3) stream sp a substitution instance of old to new in source in the context of the last $1$2reexecreexecreexecreexecreexecreexecreexecreexec performed on re->match. Each instance of where n is a digit, is replaced by the string delimited by and Each instance of $1$2&&&&&&&& is replaced by the string delimited by re->match[0].sp and re->match[0].ep. If $1$2RE_ALLRE_ALLRE_ALLRE_ALLRE_ALLRE_ALLRE_ALLRE_ALL is set in flags then all occurrences of old are replaced by new. If $1$2RE_LOWERRE_LOWERRE_LOWERRE_LOWERRE_LOWERRE_LOWERRE_LOWERRE_LOWER $1$2[[[[[[[[ is set in flags then old is converted to lower [upper] case.

$1$2reerror,reerror,reerror,reerror,reerror,reerror,reerror,reerror, called whenever an error is detected in $1$2recomp,recomp,recomp,recomp,recomp,recomp,recomp,recomp, $1$2reexec,reexec,reexec,reexec,reexec,reexec,reexec,reexec, or $1$2ressub,ressub,ressub,ressub,ressub,ressub,ressub,ressub, writes the string msg on the standard error file and exits. $1$2reerrorreerrorreerrorreerrorreerrorreerrorreerrorreerror may be replaced to perform special error processing.

DIAGNOSTICS

$1$2recomprecomprecomprecomprecomprecomprecomprecomp returns 0 for an invalid expression or other failure. $1$2reexecreexecreexecreexecreexecreexecreexecreexec returns 1 if source is accepted, 0 otherwise.

SEE ALSO

ed(1), grep(1), expr(1)