+#ifdef HAVE_PCRE2
+/*********************************************************************
+ *
+ * Function : pcre2_pattern_matches
+ *
+ * Description : Checks if a compiled pcre2 pattern matches a string.
+ *
+ * Parameters :
+ * 1 : pattern = The compiled pattern
+ * 2 : string = The string to check
+ *
+ * Returns : TRUE for yes, FALSE otherwise.
+ *
+ *********************************************************************/
+static int pcre2_pattern_matches(const pcre2_code *pattern, const char *string)
+{
+ PCRE2_SIZE offset;
+ int ret;
+ pcre2_match_data *pcre2_matches;
+
+ assert(pattern != NULL);
+ assert(string != NULL);
+
+ offset = 0;
+
+ pcre2_matches = pcre2_match_data_create_from_pattern(pattern, NULL);
+ if (NULL == pcre2_matches)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Out of memory while matching pattern against %s", string);
+ return FALSE;
+ }
+
+ ret = pcre2_match(pattern, (const unsigned char *)string, strlen(string),
+ offset, 0, pcre2_matches, NULL);
+
+ pcre2_match_data_free(pcre2_matches);
+
+ return (ret >= 0);
+}
+#endif
+
+
+/*********************************************************************
+ *
+ * Function : regex_matches
+ *
+ * Description : Checks if a compiled regex pattern matches a string
+ * using either pcre2 or pcre1 code.
+ *
+ * Parameters :
+ * 1 : pattern = The compiled pattern
+ * 2 : string = The string to check
+ *
+ * Returns : TRUE for yes, FALSE otherwise.
+ *
+ *********************************************************************/
+int regex_matches(const REGEX_TYPE *pattern, const char *string)
+{
+#ifdef HAVE_PCRE2
+ return pcre2_pattern_matches(pattern, string);
+#else
+ return (0 == regexec(pattern, string, 0, NULL, 0));
+#endif
+}
+