可以使用C++11中的正则表达式库<regex>来提取文本中的window路径。以下是一个示例代码:

#include <iostream>
#include <regex>
#include <string>

int main() {
    std::string text = "This is a sample text containing a Windows path C:\\Program Files\\Microsoft Visual Studio 11.0\\VC\\bin\\vcvars32.bat";
    std::regex pattern(R"(^[a-zA-Z]:\\(?:[^<>:"/\\|?*]+\\)*[^<>:"/\\|?*]*$)");  // 正则表达式模式,匹配window路径
    std::smatch match;

    if (std::regex_search(text, match, pattern)) {  // 查找匹配的window路径
        std::cout << "Window Path: " << match.str() << std::endl;
    } else {
        std::cout << "No Window Path Found" << std::endl;
    }

    return 0;
}

输出:

Window Path: C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat
``
C++正则提取文本里面的window路径vc11

原文地址: https://www.cveoy.top/t/topic/hlxk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录