使用regex检测带有特定前缀的DLL文件名
Detect a DLL file-name with a particular prefix using regex
我正试图使用正则表达式模式来检测dll文件名是否:
- 以
module_
开头 - 以
.dll
结尾 - 中间的字符均为非特殊字母数字字符
bool IsModule(std::string const& name)
{
static std::regex const regex("^module_[:alnum:]+\.dll");
return std::regex_match(name, regex);
}
使用在线正则表达式调试器,我无法找出问题。当我使用module_custom.dll
作为输入文件名进行测试时,它不认为它是匹配的。
[:alnum:]
字符类似乎不支持c++ 11正则表达式引擎。根据这个页面,它相当于[a-zA-Z0-9]
,所以你可以这样做:
bool IsModule(std::string const& name)
{
static std::regex const regex("^module_[a-zA-Z0-9]+\.dll$");
return std::regex_match(name, regex);
}
请注意,我在末尾添加了$
锚,正如Mike在上面的评论中提到的。如果省略它,它将认为module_custom.dllfoo
是有效匹配。
[:alnum:]
字符类是POSIX正则表达式风格的特性。我不熟悉c++中的正则表达式,但似乎默认引擎与EMACScript兼容,而不是POSIX。然而,根据这个页面,它看起来可能是可以切换到使用POSIX兼容的引擎?如果使用POSIX正则表达式语法对您很重要,也许有更有知识的人可以提供更多相关信息。
试试这个
bool IsModule(std::string const& name)
{
static std::regex const regex("^module_\w+\.dll");
return std::regex_match(name, regex);
}
不确定:alphanum:是否适用于c++ 11.
相关文章:
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
- Python ctypes:不会按预期加载 dll
- 使用regex检测带有特定前缀的DLL文件名