28 uint32_t options = PCRE2_UTF;
32 if (!(re->
regex = pcre2_compile((PCRE2_SPTR)
pattern, PCRE2_ZERO_TERMINATED, options, &errorcode, &offset, NULL))) {
33 PCRE2_UCHAR buffer[256];
34 pcre2_get_error_message(errorcode, buffer,
sizeof(buffer));
35 ELOG(
"PCRE regular expression compilation failed at %zu: %s\n",
36 (
size_t)offset, buffer);
63 pcre2_match_data *match_data;
66 match_data = pcre2_match_data_create_from_pattern(
regex->
regex, NULL);
70 rc = pcre2_match(
regex->
regex, (PCRE2_SPTR)input, strlen(input), 0, 0, match_data, NULL);
71 pcre2_match_data_free(match_data);
73 LOG(
"Regular expression \"%s\" matches \"%s\"\n",
78 if (rc == PCRE2_ERROR_NOMATCH) {
79 LOG(
"Regular expression \"%s\" does not match \"%s\"\n",
84 ELOG(
"PCRE error %d while trying to use regular expression \"%s\" on input \"%s\", see pcreapi(3)\n",
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.
void regex_free(struct regex *regex)
Frees the given regular expression.
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
Regular expression wrapper.