Regex C++: extract substring

前端 未结 4 1072
陌清茗
陌清茗 2020-12-02 23:13

I would like to extract a substring between two others.
ex: /home/toto/FILE_mysymbol_EVENT.DAT
or just FILE_othersymbol_EVENT.DAT
And I

4条回答
  •  萌比男神i
    2020-12-03 00:02

    I would study corner cases before trusting it, but

       std::string text = "/home/toto/FILE_mysymbol_EVENT.DAT";
       std::regex re("(.*)(FILE_)(.*)(_EVENT.DAT)(.*)");
       std::cout << std::regex_replace(text, re, "$3") << '\n';
    

    is a good candidate.

提交回复
热议问题