char *re_comp(s) char *s; re_exec(s) char *s; recmp(pattern,target) char *pattern, *target; #include <regex.h> struct regex { char expbuf[ESIZE]; char *braslist[NBRA]; char *braelist[NBRA]; char circf; char *start, *end; /* pointers to occurrence in 's' */ }; struct regex *re_compile(s,fold) char *s; int fold; re_match(s,r) char *s; struct regex *r;
Re_comp returns 0 if the string s was compiled successfully; otherwise a string containing an error message is returned. If re_comp is passed 0 or a null string, it returns without changing the currently compiled regular expression.
Re_exec returns 1 if the string s matches the last compiled regular expression, 0 if the string s failed to match the last compiled regular expression, and -1 if the compiled regular expression was invalid (indicating an internal error).
Recmp is analogous to strcmp(3), but takes a regular expression pattern and returns 0 if it is matched in the target string, 1 if not, or -1 on error (bad regular expression).
The strings passed to both re_comp and re_exec may have trailing or embedded newline characters; they are terminated by nulls. The regular expressions recognized are described in the manual entry for ed(1), given the above difference.
Re_compile returns a pointer to a regex structure. This information is also kept in the static area used by re_comp(); If the fold variable is true, the compiled regular expression will match either upper or lower case. It may be deallocated with free(). Re_match is the same as re_exec with an explicit regex buffer. After calling Re_match, the pointers r->start and r->end point to the beginning and end of the matched expression in s.
Re_comp returns one of the following strings if an error occurs:
Re_compile returns NULL for any of these errors.