Syntax
#include <sys/types.h> #include <regex.h> int regcomp(regex_t *preg, const char *pattern, int cflags);Description
regcomp compiles the source regular expression pointed to by pattern into an executable version and stores it in the location pointed to by preg. You can then use regexec to compare the regular expression to other strings.
The cflags flag defines the attributes of the compilation process:
REG_EXTENDED
Regular expressions are a context-independent syntax that can represent a wide variety of character sets and character set orderings, which can be interpreted differently depending on the current locale. The functions regcomp, regerror, regexec, and regfree use regular expressions in a similar way to the UNIX awk, ed, grep, and egrep commands. Regular expressions are described in more detail under "Regular Expressions" in the VisualAge C++ Programming Guide.
If regcomp is successful, it returns 0. Otherwise, it returns an error code that you can use in a call to regerror, and the content of preg is undefined.
This example compiles an extended regular expression.
#include <sys/types.h>#include <regex.h> #include <stdio.h> #include <stdlib.h> int main(void) { regex_t preg; char *pattern = ".*(simple).*"; int rc; if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED))) { printf("regcomp() failed, returning nonzero (%d)\n", rc); exit(EXIT_FAILURE); } printf("regcomp() is sucessful.\n"); return 0; /**************************************************************************** The output should be similar to : regcomp() is sucessful. ****************************************************************************/ }Related Information