Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#include <regex.h>
int regcomp(regex_t *_restrict_ preg, const char *_restrict_ pattern, int cflags);
Compiles the regular expression specified by pattern into an executable string of op-codes.
preg is a pointer to a compiled regular expression.
pattern is a pointer to a character string defining a source regular expression (described below).
The regcomp() function under z/OS XL C/C++ will use the definition of characters according to the current LC_SYNTAX category. The characters, [, ], {, }, |, ^, and $, have varying code points in different encoded character sets.
The functions regcomp(), regerror(), regexec(), and regfree() use regular expressions in a similar way to the UNIX awk, ed, grep, and egrep commands.
No assumptions are made at compile time about the actual characters contained in the range.
If you specify only m, it indicates the exact number of times to apply the regular expression. {m,} is equivalent to {m,u}. They both match m or more occurrences of the expression.
If successful, regcomp() returns 0.
If unsuccessful, regcomp() returns nonzero, and the content of preg is undefined.
⁄* CELEBR07
This example compiles an extended regular expression.
*⁄
#include <regex.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
main() {
regex_t preg;
char *string = "a simple string";
char *pattern = ".*(simple).*";
int rc;
if ((rc = regcomp(&preg, pattern, REG_EXTENDED)) != 0) {
printf("regcomp() failed, returning nonzero (%d)", rc);
exit(1);
}
}