不熟悉在 C 语言上使用正则表达式库。目前正在尝试使用Regexec() 和 Regcomp()函数来搜索与我的模式或正则表达式匹配的字符串。但我不能* t 生成我匹配的字符串。我是否遗漏了代码中的某些内容,或者函数的任何错误用法?
我的示例代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <regex.h>
int main(int argc, char ** argv)
{
regex_t r;
const char * my_regex = "(\\d+.\\d+.\\d+.\\d+)";
const char * my_string = "Am trying to match any ip like, 23.54.67.89 , in this string and 123.232.123.33 is possible";
const int no_of_matches = 10;
regmatch_t m[no_of_matches];
printf ("Trying to match '%s' in '%s'\n", my_regex, my_string);
int status = regcomp (&r, my_regex, REG_EXTENDED|REG_NEWLINE);
printf("status: …Run Code Online (Sandbox Code Playgroud)