regcomp -- Compile Regular Expression

Format

#include <regex.h>
int regcomp(regex_t *preg, const char *pattern, int cflags);

Language Level: POSIX, XPG4
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 Support extended regular expressions.
REG_NEWLINE Treat new-line character as a special end-of-line character; it then establishes the line boundaries matched by the ^ and $ patterns, and can only be matched within a string explicitly using \n. (If you omit this flag, the new-line character is treated like any other character.)
REG_ICASE Ignore case in match.
REG_NOSUB Ignore the number of subexpressions specified in pattern. When you compare a string to the compiled pattern (using regexec), the string must match the entire pattern. regexec then returns a value that indicates only if a match was found; it does not indicate at what point in the string the match begins, or what the matching string is.

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.

Return Value
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.

Example



Regular Expressions


regerror -- Return Error Message for Regular Expression
regexec -- Execute Compiled Regular Expression
regfree -- Free Memory for Regular Expression
<regex.h>