我有来自Exchange服务器的这个日志
2010-05-20T01:53:33.097Z,12.10.53.144,12.10.53.200,EXHUB-10,08CCC3F50C35F2D2;2010-05-20T01:53:32.128Z;0,EXHUB-10Default EXHUB-10,SMTP,RECEIVE,829888,norma@ccc.gov.my,521647,1,”NEAC Sub-Working Group Meeting – Upgrade Skills of the Labour Force’s and Enhance Vocational and Technical Training- 2:30 pm Monday May 24, 2010″,lee.cheesung@gmail.com,<>,00A:
我使用这个正则表达式来匹配和分组模式;
(d{4}-d{2}-d{2})(?:[ws]+)(d+:d+:d+.d+)(?:[w+d.]*),(.*?),([‘”].*[‘”]|.*?),(?:(d{4}-d{2}-d{2}wd{2}:d{2}:d{2}.d+)(?:w+)*)*(.*)
基本上,日志中的信息由逗号分隔. 不幸的是,对于“电子邮件主题”字段,如果用户输入逗号,则日志将以双引号显示,例如上面的示例 – 日期格式为“2010年5月24日星期一”的逗号
…..521647,”NEAC Sub-Working Group Meeting – Upgrade Skills of the Labour Force’s and Enhance Vocational and Technical Training- 2:30 pm Monday May 24,lee.keesung@gmail.com,…..
如何在没有特定组中的双引号的情况下将逗号与逗号一起抓取(第19组)
解决方法
你提到:
Basically,the information in the log is separated by the comma…also if a comma is part of the field the field will be double quoted.
这使它成为一个CSV文件.解析CSV文件是一个已解决的问题,您无需重新发明轮子.使用语言库提供的CSV解析器.
如果您使用的是Perl,请查看Text::CSV模块.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|