在 C 代码中,我需要检查模式是否与文件的至少一行匹配。我的表达中需要插入符号。我所拥有的是:
const char *disambiguate_pp(SourceFile *sourcefile) {
char *p = ohcount_sourcefile_get_contents(sourcefile);
char *eof = p + ohcount_sourcefile_get_contents_size(sourcefile);
/* prepare regular expressions */
pcre *re;
const char *error;
int erroffset;
re = pcre_compile("^\\s*(define\\s+[\\w:-]+\\s*\\(|class\\s+[\\w:-]+(\\s+inherits\\s+[\\w:-]+)?\\s*{|node\\s+\\'[\\w:\\.-]+\\'\\s*{)",
PCRE_MULTILINE, &error, &erroffset, NULL);
for (; p < eof; p++) {
if (pcre_exec(re, NULL, p, mystrnlen(p, 100), 0, 0, NULL, 0) > -1)
return LANG_PUPPET;
}
return LANG_PASCAL;
}
出于某种原因,插入符号似乎被忽略了,因为以下行与正则表达式匹配(并且不应该):
// update the package block define template (the container for all other
我尝试了很多东西,但无法使其正常工作。我究竟做错了什么?