2 #define I3__FILE__ "regex.c"
26 int errorcode, offset;
30 int options = PCRE_UTF8;
36 while (!(re->
regex = pcre_compile2(pattern, options, &errorcode, &error, &offset, NULL))) {
39 if (errorcode == 32) {
40 options &= ~PCRE_UTF8;
43 ELOG(
"PCRE regular expression compilation failed at %d: %s\n",
52 ELOG(
"PCRE regular expression studying failed: %s\n", error);
80 if ((rc = pcre_exec(regex->
regex, regex->
extra, input, strlen(input), 0, 0, NULL, 0)) == 0) {
81 LOG(
"Regular expression \"%s\" matches \"%s\"\n",
86 if (rc == PCRE_ERROR_NOMATCH) {
87 LOG(
"Regular expression \"%s\" does not match \"%s\"\n",
92 ELOG(
"PCRE error %d while trying to use regular expression \"%s\" on input \"%s\", see pcreapi(3)\n",
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
void regex_free(struct regex *regex)
Frees the given regular expression.
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression...
bool regex_matches(struct regex *regex, const char *input)
Checks if the given regular expression matches the given input and returns true if it does...
Regular expression wrapper.