我正在尝试使用下面的代码解析uevent,但我认为我的正则表达式不正确,导致regcomp函数失败。
有人能帮上忙吗?我正在尝试做一些像this这样的事情。
#include <stdio.h>
#include <string.h>
#include <regex.h>
int main ()
{
char * source = "change@/devices/soc/799999.i2c/i2c-3/3-0015/power_supply/battery";
char * regexString = "(?<action>[a-zA-Z]+)@\\/(?<dev_path>.*)\\/(?<subsystem>[a-zA-z]+)\\/(?<name>[a-zA-z]+)";
size_t maxGroups = 4;
regex_t regexCompiled;
regmatch_t groupArray[maxGroups];
if (regcomp(®exCompiled, regexString, REG_EXTENDED))
{
printf("Could not compile regular expression.\n");
return 1;
};
regfree(®exCompiled);
return 0;
}我得到“无法编译正则表达式。”。这意味着regcomp无法识别regex。
https://stackoverflow.com/questions/47564391
复制相似问题