zoukankan      html  css  js  c++  java
  • C++正则表达式笔记之wregex

    遍历所有匹配

    #include <iostream>
    #include <regex>
    using namespace std;
    int main()
    {
        wstring wstr = L"我是1994年出生的,我今年25岁了。";
        wsmatch wsm;
        wregex wre(L"[0-9]+");
        wsregex_iterator itr1(wstr.begin(), wstr.end(), wre);
        wsregex_iterator itr2;
        for (wsregex_iterator itr = itr1; itr != itr2; ++itr)
        {
            wcout << itr->str() << endl;
        }
        return 0;
    }

    在目标文本中进行搜索

    #include <iostream>
    #include <regex>
    using namespace std;
    int main()
    {
        wstring text = L"百度搜索引擎https://www.baidu.com/^_^";
        wsmatch wsm;
        wregex wre(L"https?://(.+?)/");
        if (regex_search(text, wsm, wre))
        {
            wcout << wsm.str(1) << endl;
        }
        const wchar_t *str = L"百度搜索引擎https://www.baidu.com/^_^";
        wcmatch wcm;
        if (regex_search(str, wcm, wre))
        {
            wcout << wsm[1] << endl;
        }
        return 0;
    }

    完全匹配

    #include <iostream>
    #include <regex>
    using namespace std;
    int main()
    {
        wstring text = L"long long ago";
        wstring text2 = L"long long";
        wregex wre(L".+ng");
        wcout << boolalpha << regex_match(text, wre) << endl;
        wcout << regex_match(text2, wre) << endl;
        return 0;
    }
  • 相关阅读:
    七。进度管理
    六。质量管理
    五。项目范围管理
    四。项目整体管理
    三。项目立项管理
    二。项目的一般只知识
    一。项目管理的管理领域
    8.BGP
    英语词汇基础
    vim中输入tab符
  • 原文地址:https://www.cnblogs.com/buyishi/p/10440944.html
Copyright © 2011-2022 走看看