我要提取这个:20110604-092737<\INFO :0xb7f2a6d0>
但是代码总是出现如下错误:
代码如下:
#include <string>
#include <iostream>
#include <regex>
#include <stdio.h>
int main()
{
std::string str = "20110604-092737<INFO :0xb7f2a6d0>: Player logout: 忘了爱过谁";
std::regex rgx("^[\\d\\-\\d\\<\\w\\s{0,1}\\:\\w>]");
std::smatch result;
if (std::regex_search(str, result, rgx))
{
std::cout << result.str();
}
}
在vc2010下运行通过,这个更简洁:
std::regex rgx("^\\d*-\\d*<\\w*\\s{0,1}:\\w*>");
std::regex rgx("^[\\d]*[-][\\d]*[<][\\w]*[\\s{0,1}][:][\\w]*[>]");
正则就没有写对
\\d{8}\\-\\d{6}\\<\\\\INFO\\s\\:0x[0-9a-fA-F]{8}\\>
现学现卖,最后就这样了:
std::regex rgx("\\d*-\\d*<\\w* :\\w*>");