c++ - 使用 std::regex 或 boost::regex 库匹配所有以“.txt”结尾的文件的正则表达式是什么?
问题描述
我正在浏览某个目录并想打印所有以 .txt 结尾的文件。此代码不起作用。
ft::FilePath 文件路径;std::filesystem::recursive_directory_iterator iter(m_rootDirectoryPath);
const std::regex e("*.txt");
for(;iter != std::filesystem::end(iter); ++iter)
{
if(std::regex_match(iter->path().string(),e))
{
const std::string& p = iter->path().string();
uint64_t pos = p.find(m_rootDirectoryPath.string());
filePath.set_path(p.substr(pos + m_rootDirectoryPath.string().size()));
writer->Write(filePath);
}
}
匹配所有以 .txt 结尾的文件的正则表达式是什么?(你必须假设我使用 std::regex 来匹配模式)
解决方案
".*\\.txt$"
您的表达式是 shell 中使用的一个 glob。
推荐阅读
- sql - 如何在 SQL (Bigquery) 中只加入和保留最新的行
- node.js - NodeJS 在多个 PUG 文件中插入 Swagger-UI
- python - Python 键盘模块的功能在 macOS 上不起作用
- javascript - 如何使用 d3.js 将图例添加到传单地图
- apache-spark - 如何使用 pyspark 从 athena 表中获取最新分区?
- go - 如何在 swagger ui 中包含模型
- c++ - Visual Studio 链接器错误:多次指定对象
- python - 合并字典中的列表并删除重复项
- php - 如何在 Myth/Auth 库 Code Igniter 4 中获取用于登录的当前电子邮件
- mysql - 如何使用现有卷(mariadb)重新启动 docker-compose