带有逗号且不带引号的csv的正则表达式 [英] Regular expression for csv with commas and no quotes

查看:113
本文介绍了带有逗号且不带引号的csv的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析非常复杂的csv,该csv会在没有引号的情况下生成带有逗号的列.
我得到的唯一提示是,字段中包含逗号前后的逗号.

I'm trying to parse really complicated csv, which is generated wittout any quotes for columns with commas.
The only tip I get, that commas with whitespace before or after are included in field.

Jake,HomePC,Microsoft VS2010, Microsoft Office 2010

应解析为

Jake
HomePC
Microsoft VS2010, Microsoft Office 2010

任何人都可以建议如何在列正文中包含"\ s"和"\ s".

Can anybody advice please on how to include "\s," and ,"\s" to column body.

推荐答案

如果您的语言支持后置断言,请拆分

If your language supports lookbehind assertions, split on

(?<!\s),(?!\s)

在C#中:

string[] splitArray = Regex.Split(subjectString, 
    @"(?<!\s) # Assert that the previous character isn't whitespace
    ,         # Match a comma
    (?!\s)    # Assert that the following character isn't whitespace", 
    RegexOptions.IgnorePatternWhitespace);

这篇关于带有逗号且不带引号的csv的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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