.TH regsub() "" "" "Regular-Expression Function (libc)"
.PC "Use regular expression to build a string"
\fB "#include <regexp.h>"
\fBregsub(\fIexpression\^\fB, \fIsource\^\fB, \fIdest\^\fB)\fR
\fBregexp *\fIexpression\^\fB;\fR
\fBchar *\fIsource\^\fB, *\fIdest\^\fB;\fR
.PP
Function
.B regsub()
builds a string from a string and a regular expression.
.PP
.I source
is the source string that is being interpreted.
.I expression
is the regular expression through which
.I source
is being interpreted; it must have been built by a call to
.BR regcomp() .
Before you call
.BR regsub() ,
you must first have called
.BR regexec()
to compare them and initialize the sub-string pointers within
.IR expression .
.PP
.I dest
points to the memory into which
.B regsub()
writes its substituted string.
It replaces each instance of `&' within
.I source
with the substring indicated by
.B startp[0]
and
.BR endp[0] .
It also replaces each instance of `\e\fIn\fR', where \fIn\fR is a digit,
with the substring
\fBstartp\fR[\fIn\^\fB]\fR and \fBendp\fR[\fIn\^\fB]\fR.
.PP
For details on how these pointers are initialized, see the Lexicon entry for
.BR regsub() .
For more details on the structure
.BR regexp ,
see the Lexicon entry for
.BR regexp.h .
The rules that describe a regular expression also appear in function
.BR regexp.h .
.SH "See Also"
.Xr "libc," libc
.Xr "regexp.h" regexp.h

