冲冲冲冲是

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <pcre.h> int main() { const char *input_string = "(15:00:32 2023 user.info root:wificommon(repacd):guest password new_value:12345678,old_value:12345678)"; const char *pattern = "new_value:(\\d+),old_value:(\\d+)"; int ovector[30]; // 存放匹配位置的数组 pcre *re; const char *error; int erroffset; int rc; re = pcre_compile(pattern, 0, &error, &erroffset, NULL); if (re == NULL) { printf("编译正则表达式失败: %s\n", error); return 1; } rc = pcre_exec(re, NULL, input_string, strlen(input_string), 0, 0, ovector, sizeof(ovector)/sizeof(int)); if (rc < 0) { printf("正则匹配失败\n"); pcre_free(re); return 1; } // 获取匹配到的字段 char *new_value = NULL; char *old_value = NULL; pcre_get_substring(input_string, ovector, rc, 1, (const char **)&new_value); pcre_get_substring(input_string, ovector, rc, 2, (const char **)&old_value); printf("new_value: %s\n", new_value); printf("old_value: %s\n", old_value); pcre_free(re); pcre_free_substring(new_value); pcre_free_substring(old_value); return 0; }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值