我正在使用 SLRE ( https://code.google.com/p/slre/ )
我正在以这种方式检查 15 个具有不同正则表达式的字符串:
struct slre slre;
struct cap captures[4 + 1];
int i = 0;
int numberOfSettings = 15;
for (i; i < numberOfSettings; i++) {
if (!slre_compile(&slre, settings[i].regex)) {
printf("Error compiling RE: %s\n", slre.err_str);
}
else if (!slre_match(&slre, settings[i].value, strlen(settings[i].value), captures)) {
printf("\nSetting '%s' does not match the regular expression!", settings[i].internName);
}
}
我使用 ( settings[i].regex
) 解析 IP 地址的正则表达式是:
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
检查 ( settings[i].value
) 的值为8.8.8.8
我也在使用与 javascript 相同的正则表达式,它们按预期工作。
有谁知道为什么这会返回错误?