V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
paparika

求助一个简单的 c++正则

  •  
  •   paparika · Sep 3, 2018 · 3674 views
    This topic created in 2807 days ago, the information mentioned may be changed or developed.

    假设有这样一个串,"fsdfsda13124tag=cpp;2343dfdadf" 我现在已经可以提取出 tag=cpp;了。试问如何能提取出 cpp 这部分?

    string s = "fsdfsda13124tag=cpp;2343dfdadf";
    
    _test_regex(s, "tag=(.*?);", result);
    
    void _test_regex(string s, string regex, string& result){
    
        std::smatch m;
        std::regex e (regex);
    
        std::regex_search (s, m, e);
        for (auto x=m.begin();x!=m.end();x++){
            result = x->str();
            break;
        }
    
    }
    
    
    paparika
        1
    paparika  
    OP
       Sep 3, 2018
    或者用 sscanf 完成这一步?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3453 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 70ms · UTC 11:21 · PVG 19:21 · LAX 04:21 · JFK 07:21
    ♥ Do have faith in what you're doing.