我使用slre(https://code.google.com/p/slre/)爲c程序提供正則表達式庫。正則表達式中的點(正則表達式)
我想匹配下列模式的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])$"
我得到以下編譯錯誤:警告:未知excape序列「\」。 我也試過用'\\'。 - >編譯錯誤消失了,但它仍然說它不匹配。
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);
}
設置[I] .regex是一個char *與上面我 設置[I]。價值提到的正則表達式我試圖匹配一個char * 字符串被8.8.8.8
有沒有其他的方法來檢查點?
把特殊字符的字符類(在你的case'[。]')被認爲是最佳做法。 –
在正則表達式中'\ .'是檢查點的正確方法,'\\。'是在C字符串中表示它的正確方法。請在您嘗試匹配的地方提供代碼。 –
匹配IPv4地址,而不是URL。 – nhahtdh