[英]c++ regular expression to list all files in a directory except hidden files (start with .)
I have a string array of the list of directory contents.我有一个目录内容列表的字符串数组。
I want to list all the strings that don't start with "."我想列出所有不以“.”开头的字符串。
So, from the list, the regex should not include ".hid.mp3"
, ".Hidden.txt"
.因此,从列表中,正则表达式不应包含
".hid.mp3"
、 ".Hidden.txt"
。
Can someone suggest the fileRegex for the following code?有人可以为以下代码建议 fileRegex 吗?
string fileList[] = {"test.png", "Hellozip.zip", "123.mp3", "hid.mp3", "hid.file.png", "sp ace.png", "comm(a.mp3", ".Hidden.txt"};
for(auto& file : fileList)
{
if (std::regex_match(file, std::regex(fileRegex, std::regex_constants::icase)) == true)
{
cout << file << " - Match\n";
}
else
{
cout << file << " - No Match\n";
}
}
Expected output should be:预计 output 应该是:
test.png - Match
Hellozip.zip - Match
123\.mp3 - Match
.hid.mp3 - No Match
hid.file.png - Match
sp ace.png - Match
comm(a.mp3 - Match
.Hidden.txt - No Match
I tried this, but it did not work:我试过这个,但没有用:
"\[\\w-\]*\\.{0,1}\[\\w- ()\]*\\.(png|jpg|zip|mp3|txt)"
Edited: I can handle ".", ".." as special case, so removed from the question.编辑:我可以处理“。”,“..”作为特殊情况,因此从问题中删除。
how about怎么样
^[^.].*$
seems to work似乎工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.