问题:
我知道可以通过以下方式获取文件名:
std::string wholePath = "/User/home/Lib/hello.cpp.h";
std::regex e(".*\\/(.*)\\..*$");
std::smatch sm;
std::regex_match(wholePath.cbegin(), wholePath.cend(), sm, e);
std::cout << "File Name is : " << sm[1];
但是我不知道如何从中获取文件名:
std::string wholePath = "\User\home\Lib\hello.cpp.h";
std::regex e_1(".*\(.*)\\..*$");
std::regex e_2(".*\\(.*)\\..*$");
std::regex e_3(".*\\\(.*)\\..*$");
std::regex e_4(".*\\\\(.*)\\..*$");
std::smatch sm;
// std::regex_match(wholePath.cbegin(), wholePath.cend(), sm, e);
我已经尝试了上述四个表达式,但它们不起作用。
我的问题是,如何匹配字符'\'。
帮助 /。\
通常'\'
应更改为'\\'
双引号内。
std::string wholePath = "\\User\\home\\Lib\\hello.cpp.h";
std::regex e(".*\\\\(.*)\\..*$");
但是此方法似乎不适用于拆分Windows路径或Unix路径
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句