pcre匹配后出现什么样的结果
答案:1 悬赏:30 手机版
解决时间 2021-03-22 03:43
- 提问者网友:且恨且铭记
- 2021-03-21 14:36
pcre匹配后出现什么样的结果
最佳答案
- 五星知识达人网友:躲不过心动
- 2021-03-21 15:38
参考如下代码:
#include
#include
#include
int main()
{
pcre *re;
const char *error;
int errorOffset, i = 0;
int oveccount = 2, ovector[oveccount];
int rc;
int exec_offset = 0;
const char *captured_string;
char *subject = "1t2t3t4t5t6t7t8t9t0tatbtct黄t避孕t";
char *pattern = "[^t]+t";
re = pcre_compile( pattern, PCRE_CASELESS, &error, &errorOffset, NULL );
if ( re == NULL ) {
printf("compilation failed at offset%d: %s
", errorOffset, error);
return 0;
}
do {
// exec_offset偏移量 默认从1开始,然后循环的时候从匹配到的结果开始
rc = pcre_exec( re, NULL, subject, strlen(subject), exec_offset, 0, ovector, oveccount );
if ( rc > 0 ) {
// 获取到匹配的结果
pcre_get_substring( subject, ovector, rc, 0, &captured_string );
printf("captured string : %s
", captured_string);
// 设置偏移量
exec_offset = ovector[1];
i++;
}
} while ( rc > 0 );
printf("match %d
", i);
return 0;
}
#include
#include
#include
int main()
{
pcre *re;
const char *error;
int errorOffset, i = 0;
int oveccount = 2, ovector[oveccount];
int rc;
int exec_offset = 0;
const char *captured_string;
char *subject = "1t2t3t4t5t6t7t8t9t0tatbtct黄t避孕t";
char *pattern = "[^t]+t";
re = pcre_compile( pattern, PCRE_CASELESS, &error, &errorOffset, NULL );
if ( re == NULL ) {
printf("compilation failed at offset%d: %s
", errorOffset, error);
return 0;
}
do {
// exec_offset偏移量 默认从1开始,然后循环的时候从匹配到的结果开始
rc = pcre_exec( re, NULL, subject, strlen(subject), exec_offset, 0, ovector, oveccount );
if ( rc > 0 ) {
// 获取到匹配的结果
pcre_get_substring( subject, ovector, rc, 0, &captured_string );
printf("captured string : %s
", captured_string);
// 设置偏移量
exec_offset = ovector[1];
i++;
}
} while ( rc > 0 );
printf("match %d
", i);
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯