C++正则表达式之获取子字符串


二话不说,直接举个简单的例子吧。

假如要从http://192.168.15.22:8888 取出192.168.15.22,用以下代码搞定

std::regex reg("(\\d+\\.\\d+\\.\\d+\\.\\d+):\\d{2,5}");
    std::smatch match;
    const std::string& proxy_ip = "http://192.168.15.22:8888/index.html";
    if (std::regex_search(proxy_ip, match, reg) && match.size() >= 2) {
        std::string ip = match[1];
        std::cout << ip; //输出192.168.15.22
    }




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM