×
Namespaces

Variants
Actions
Revision as of 08:14, 13 August 2012 by hamishwillee (Talk | contribs)

Archived:Open C/C++: 使用正则表达式的缓慢问题

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
文章
翻译:
hoolee
最后由 hamishwillee 在 13 Aug 2012 编辑
  • 详细描述

当使用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++插件修正了这一问题

199 page views in the last 30 days.
×