I m trying to write an expression that would filter out several types of directories and files when listing the contents of a directory. Namely, I want to avoid listing the current directory (.), upper directory (..), hidden files and other more specific directories.
这是我现在的事情:
<代码>[+]/[+]/>>
However, it doesn t match .
, ..
, recycle_bin nor cgi-bin
. If I remove all the |
operands and leave the expression to only [\.+]
, it works (matches .
, ..
, etc). Which is strange, because I m pretty sure |
= OR. Do I miss something?
附录 1. 此处使用守则一:
regex_t regex;
int reti;
char msgbuf[100];
/* Compile regular expression */
reti = regcomp(®ex, "[\.+]|cgi-bin|recycle_bin", 0);
if( reti )
{
fprintf(stderr, "Could not compile regex
");
exit(1);
}
reti = regexec(®ex, entry->d_name, 0, NULL, 0);
if( !reti ){
printf("directoy %s found -> %s", path, entry->d_name);
printf("
");
}
else if( reti == REG_NOMATCH ){
//if the directory is not filtered out, we add it to the watch list
printf("good dir %s", entry->d_name);
printf("
");
}
else{
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s
", msgbuf);
}