正则表达式应该拆分,包含在 CSV 文件中的双引号之外吗? [英] regular expression should split , that are contained outside the double quotes in a CSV file?

查看:37
本文介绍了正则表达式应该拆分,包含在 CSV 文件中的双引号之外吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是样本

"abc","abcsds","adbc,ds","abc"

输出应该是

abcabcsdsadbc,ds美国广播公司

解决方案

如果您可以确定没有内部转义引号,那么我猜测可以为此使用正则表达式.但是,大多数现代语言已经有了合适的 CSV 解析器.

使用合适的解析器是正确的答案.Text::CSV 用于 Perl,例如.>

但是,如果您一味地使用正则表达式,我建议您从某种模块中借用",例如:http://metacpan.org/pod/Regexp::Common::balanced

This is the sample

"abc","abcsds","adbc,ds","abc"

Output should be

abc
abcsds
adbc,ds
abc

解决方案

If you can be sure there are no inner, escaped quotes, then I guess it's ok to use a regular expression for this. However, most modern languages already have proper CSV parsers.

Use a proper parser is the correct answer to this. Text::CSV for Perl, for example.

However, if you're dead set on using regular expressions, I'd suggest you "borrow" from some sort of module, like this one: http://metacpan.org/pod/Regexp::Common::balanced

这篇关于正则表达式应该拆分,包含在 CSV 文件中的双引号之外吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆