您的位置:首页 > 其它

正则表达式

2015-07-17 10:04 459 查看
#include <iostream>

#include <string>

#include <regex>

int main(void)

{
std::string str("2015-07-07 15:42:50,666 INFO org.apache.hadoop.hdfs.server.datanode.DataNode.clienttrace: src: /10.215.145.89:9003, dest: /10.196.139.31:38385, bytes: 17660496, op: HDFS_READ, cliID: DFSClient_attempt_1435652218972_8928036_m_000228_0_1283375306_1,
offset: 0, srvID: DS-885471072-10.215.145.89-9003-1416312428093, blockid: BP-1531210715-10.215.135.49-1416303685693:blk_1256393234_183414267, duration: 32839633797");
std::regex reg("(^[^,]+?),.+bytes: ([^,].+?),.+op: ([^,]+?),.+cliID: DFSClient_attempt([^,]+)_m");
std::smatch match;
std::string result("");
std::regex_search(str, match, reg);
/* op */
result += match[3];
result.append("|");
/* date */
result += match[1];
result.append("|");
/* application */
result.append("application");
result += match[4];
result.append("|");
/* bytes */
result += match[2];
std::cout <<  result  << std::endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: