以下是一个示例代码,使用了C++11中的正则表达式库来提取window路径:

#include <regex>
#include <iostream>

int main() {
    std::string text = "wTitle = 地址: D:\\Work\\gst\\文档\\脚本";
    std::regex path_regex(R"(([A-Za-z]:\\[\w\\]*)+)");

    std::smatch path_match;
    if (std::regex_search(text, path_match, path_regex)) {
        std::cout << "Window路径:" << path_match.str() << std::endl;

        // 将匹配到的路径保存到char*中
        const char* path = path_match.str().c_str();
        std::cout << "保存的char*路径:" << path << std::endl;
    }

    return 0;
}

输出:

Window路径:D:\Work\gst\文档\脚本
保存的char*路径:D:\Work\gst\文档\脚本

注意,在保存到char*中时,需要使用std::string的c_str()函数来获取指向字符串的指针

C++正则提取文本里面的window路径文本wTitle = 地址 DWorkgst文档脚本和wTitle = 地址 C结果用char保存vc11

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

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