正则表达式
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;
}
#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;
}
相关文章推荐
- 当装了两个tomcat后,如何修改tomcat端口
- [Vijos 1404]遭遇战
- two sum
- MySQL的varchar定义长度到底是字节还是字符
- The General Procedure Of Setting Up EDKII Development Environment:搭建EDKII开发环境的通用流程[2.1]
- 关于quartus ii软件中注释乱码问题的解决方法
- hdoj1903
- 动态计算UITableViewCell高度详解
- 解决VM克隆网卡无法识别
- Laucnher3如何实现给hotseat上的应用显示title
- leetCode(39):Lowest Common Ancestor of a Binary Tree
- Java 重写hashCode 方法和equals方法
- 经典SQL语句大全
- leetCode(39):Lowest Common Ancestor of a Binary Tree 分类: leetCode 2015-07-17 10:03 114人阅读 评论(0) 收藏
- 金错刀:【马化腾的红包:一款7星级产品如何炼成?】
- 最后一周 银行储蓄系统
- HDU 1005 Number Sequence
- js 关于table的操作
- C++11/14 lamba, 仿函数 对比
- error PRJ0019:A Tool returned an error code from"XX.moc"