Node:Regexp Cleanup, Previous:Subexpression Complications, Up:Regular Expressions
When you are finished using a compiled regular expression, you can
free the storage it uses by calling regfree
.
void regfree (regex_t *compiled) | Function |
Calling regfree frees all the storage that *compiled
points to. This includes various internal fields of the regex_t
structure that aren't documented in this manual.
|
You should always free the space in a regex_t
structure with
regfree
before using the structure to compile another regular
expression.
When regcomp
or regexec
reports an error, you can use
the function regerror
to turn it into an error message string.
size_t regerror (int errcode, regex_t *compiled, char *buffer, size_t length) | Function |
This function produces an error message string for the error code
errcode, and stores the string in length bytes of memory
starting at buffer. For the compiled argument, supply the
same compiled regular expression structure that regcomp or
regexec was working with when it got the error. Alternatively,
you can supply NULL for compiled; you will still get a
meaningful error message, but it might not be as detailed.
If the error message can't fit in length bytes (including a
terminating null character), then The return value of Here is a function which uses char *get_regerror (int errcode, regex_t *compiled) { size_t length = regerror (errcode, compiled, NULL, 0); char *buffer = xmalloc (length); (void) regerror (errcode, compiled, buffer, length); return buffer; } |