.TH regexec() "" "" "Regular-Expression Function (libc)"
.PC "Compare a string with a regular expression"
.B "#include <regexp.h>"
\fBint regexec(\fIexpression\^\fB, \fIstring\^\fB)\fR
\fBregexp *\fIexpression\^\fB;\fR
\fBchar *\fIstring\^\fB;\fR
.PP
Function
.B regexec()
compares
.I string
with
.IR expression ,
which is a regular expression compiled by function
.BR regcomp() .
If
.I string
matches
.IR expression ,
.B regexec()
returns one; otherwise, it returns zero and readjusts the sub-string pointers
within
.IR expression .
.PP
For details on the structure
.B regexp
and its sub-string pointers, see the Lexicon entry for
.BR regexp.h .
In brief, if
.B regexec()
successfully matches
.I string
with
.IR expression ,
it initializes arrays
.B startp[]
and
.B endp[]
within
.IR expression .
Each
.B startp/endp
pair point to one substring within
.IR string :
the
.B startp
element points to the first character of the substring and the
.B endp
element points to the first character that follows the substring.
The pair
.B startp[0]/endp[0]
points to the substring of
.I string
that matched the whole of
.IR expression .
The other pairs point to the substrings within
.I string
that matched parenthesized expressions within
.IR expression ,
with parenthesized expressions numbered
in left-to-right order of their opening parentheses.
.SH "See Also"
.Xr "libc," libc
.Xr "regexp.h" regexp.h
