Next: BSD Searching, Up: BSD Regex Functions [Contents][Index]
With Berkeley Unix, you can only search for a given regular
expression; you can’t match one. To search for it, you must first
compile it. Before you compile it, you must indicate the regular
expression syntax you want it compiled according to by setting the
variable re_syntax_options
(declared in regex.h) to some
syntax (see Regular Expression Syntax).
To compile a regular expression use:
char * re_comp (char *regex)
regex is the address of a null-terminated regular expression.
re_comp
uses an internal pattern buffer, so you can use only the
most recently compiled pattern buffer. This means that if you want to
use a given regular expression that you’ve already compiled—but it
isn’t the latest one you’ve compiled—you’ll have to recompile it. If
you call re_comp
with the null string (not the empty
string) as the argument, it doesn’t change the contents of the pattern
buffer.
If re_comp
successfully compiles the regular expression, it
returns zero. If it can’t compile the regular expression, it returns
an error string. re_comp
’s error messages are identical to those
of re_compile_pattern
(see GNU Regular Expression Compiling).