你有pcre2-jit怎么使用的示例代码嘛
时间: 2023-04-02 13:04:49 浏览: 246
pcre在windows下面的示例代码
5星 · 资源好评率100%
以下是一个简单的 pcre2-jit 使用示例代码:
#include <stdio.h>
#include <pcre2.h>
int main() {
PCRE2_SPTR pattern = (PCRE2_SPTR)"hello";
PCRE2_SPTR subject = (PCRE2_SPTR)"hello world";
int errornumber;
PCRE2_SIZE erroroffset;
pcre2_code *re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, , &errornumber, &erroroffset, NULL);
if (re == NULL) {
PCRE2_UCHAR buffer[256];
pcre2_get_error_message(errornumber, buffer, sizeof(buffer));
printf("PCRE2 compilation failed at offset %d: %s\n", (int)erroroffset, buffer);
return 1;
}
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re, NULL);
int rc = pcre2_jit_match(re, subject, PCRE2_ZERO_TERMINATED, , , match_data, NULL);
if (rc < ) {
printf("PCRE2 matching failed: %d\n", rc);
return 1;
}
printf("Match succeeded at offset %d\n", (int)match_data[].ovector[]);
pcre2_match_data_free(match_data);
pcre2_code_free(re);
return ;
}
阅读全文