In gnu, you can both match and search for a given regular expression. To do either, you must first compile it in a pattern buffer (see GNU Pattern Buffers).
Regular expressions match according to the syntax with which they were
compiled; with gnu, you indicate what syntax you want by setting
re_syntax_options (declared in regex.h)
before calling the compiling function,
below). See Syntax Bits, and Predefined Syntaxes.
You can change the value of
re_syntax_options at any time.
Usually, however, you set its value once and then never change it.
re_compile_pattern takes a pattern buffer as an argument. You
must initialize the following fields:
re_compile_patternto allocate memory for the compiled pattern, set both of these to zero. If you have an existing block of memory (allocated with
malloc) you want Regex to use, set
bufferto its address and
allocatedto its size (in bytes).
realloc to extend the space for
the compiled pattern as necessary.
To compile a pattern buffer, use:
char * re_compile_pattern (const char *regex, const int regex_size, struct re_pattern_buffer *pattern_buffer)
regex is the regular expression's address, regex_size is its length, and pattern_buffer is the pattern buffer's address.
re_compile_pattern successfully compiles the regular
expression, it returns zero and sets
*pattern_buffer to the
compiled pattern. It sets the pattern buffer's fields as follows:
re_compile_pattern can't compile regex, it returns an
error string corresponding to a posix error code.