SLRE正则表达式不起作用

时间:2013-05-17 19:39:58

标签: c regex

我正在使用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,它们按预期工作。

有没有人知道为什么会返回false?

1 个答案:

答案 0 :(得分:2)

SLRE不支持| - 请参阅slre.h中的“支持的语法”部分。

(除非您有特殊原因,否则我建议您使用PCRE。)

相关问题