正则表达式 - 如果模式匹配,则替换双引号之间的字符(逗号)
我有来自 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-10\默认 EXHUB-10,SMTP,RECEIVE,829888,,[电子邮件受保护], ,521647,1,,,"NEAC 分工作组会议-升级 劳动力的技能和 加强职业技术 培训 - 5 月 24 日星期一下午 2:30 2010",[电子邮件受保护],<>,00A:< /p>
和我使用这个正则表达式来匹配和分组模式;
(\d{4}-\d{2}-\d{2})(?:[\w\s]+)(\d+:\d+:\d+.\d+)(?:[ \w+\d.]*),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?) ,(.*?),(.*?),(.*?),(.*?),(['"].*['"]|.*?),(.*?),(. *?),(.*?),(.*?),(.*?),(.*?),(.*?),(?:(\d{4}-\d{2}- \d{2}\w\d{2}:\d{2}:\d{2}.\d+)(?:\w+)*)*(.*)
日志中的信息基本上都是用逗号分隔的。 不幸的是,对于“电子邮件主题”字段,如果用户输入逗号,日志将显示在双引号中,如上面的示例 - 日期格式中的逗号 “Monday May 24, 2010”
.....521647,1,,,"NEAC子工作 小组会议 - 提升团队技能 劳动力和职业提升 和技术培训 - 周一下午 2:30 5月24日, 2010",[电子邮件受保护],.....
我怎样才能在特定组(第 19 组)中抓取整个主题以及逗号,不带双引号
I have this log from Exchange server
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-10\Default
EXHUB-10,SMTP,RECEIVE,829888,,[email protected],,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",[email protected],<>,00A:
and i used this regex to match and group the pattern;
(\d{4}-\d{2}-\d{2})(?:[\w\s]+)(\d+:\d+:\d+.\d+)(?:[\w+\d.]*),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(['"].*['"]|.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(?:(\d{4}-\d{2}-\d{2}\w\d{2}:\d{2}:\d{2}.\d+)(?:\w+)*)*(.*)
Basically, the information in the log is separated by the comma.
Unfortunately, for the 'email subject' field, if the user enter the comma, the log will appear in double quote such as the above example - comma in the date format "Monday May 24, 2010"
.....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",[email protected],.....
How can i grab the whole subject together with the comma without the double quote in the specific group(19th group)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于java使用Apache commons:
http://commons.apache.org/sandbox/csv/
For java use Apache commons:
http://commons.apache.org/sandbox/csv/
你提到:
这使其成为 CSV 文件。解析 CSV 文件是一个已解决的问题,您无需重新发明轮子。使用语言库提供的 CSV 解析器。
如果您使用 Perl,请查看 Text::CSV 模块。
You mention:
which makes it a CSV file. Parsing a CSV file is a solved problem and you need not reinvent the wheel. Use a CSV parser provided by your language library.
If you are using Perl take a look at the Text::CSV module.
您给出的行似乎是 CSV 格式。为什么不使用 CSV 解析器来解析它,例如:
The line you gave seems to be in a CSV format. Why not parse it using a CSV parser, such as: