Open C/C++: 使用正则表达式的缓慢问题
文章信息
- 详细描述
当使用regex.h的regcomp方法编译某个正则表达式时会出现慢的情况:
regex_t preg;
char* str = "192.168.1.123";
char* pattern = "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})";
int rc;
size_t nmatch = 5;
regmatch_t pmatch[5];
//the next line will take 30-60 seconds to evaluate
if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED )))
{
printf("Regular expression compiling failed");
int c = getchar();
return false;
}
解决方案 最新版本的Open C/C++插件修正了这一问题


(no comments yet)