正则表达式查找逗号不在引号内 [英] Regex find comma not inside quotes
本文介绍了正则表达式查找逗号不在引号内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 C# 中逐行检查
I'm checking line by line in C#
示例数据:
bob jones,123,55.6,,,"Hello , World",,0
jim neighbor,432,66.5,,,Andy "Blank,,1
john smith,555,77.4,,,Some value,,2
正则表达式选择引号外的逗号 无法解析第二行,这是最接近的.
Regex to pick commas outside of quotes doesn't resolve second line, it's the closest.
推荐答案
退后一步,大吃一惊!
<小时>这是您要查找的正则表达式:
Stand back and be amazed!
Here is the regex you seek:
(?!\B"[^"]*),(?![^"]*"\B)
这是一个演示:
- 它与第二行不匹配,因为您插入的
"
没有右引号. - 它不会匹配这样的值:
,r"a string",10
因为"
边缘的字母将创建一个单词边界,而不是非单词边界.
- It does not match the second line because the
"
you inserted does not have a closing quotation mark. - It will not match values like so:
,r"a string",10
because the letter on the edge of the"
will create a word boundary, rather than a non-word boundary.
(".*?,.*?"|.*?(?:,|$))
这将匹配内容和逗号,并与充满标点符号的值兼容
This will match the content and the commas and is compatible with values that are full of punctuation marks
这篇关于正则表达式查找逗号不在引号内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文