在CSV文件中查找未转义的双引号的正则表达式 [英] Regular expression to find unescaped double quotes in CSV file

查看:217
本文介绍了在CSV文件中查找未转义的双引号的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正则表达式是什么来找到由两个非转义双引号组成的集合,这些双引号包含在CSV文件中双引号引起的列中?

What would a regular expression be to find sets of 2 unescaped double quotes that are contained in columns set off by double quotes in a CSV file?

不匹配:

"asdf","asdf"
"", "asdf"
"asdf", ""
"adsf", "", "asdf"

匹配:

"asdf""asdf", "asdf"
"asdf", """asdf"""
"asdf", """"


推荐答案

尝试:

(?m)""(?![ \t]*(,|$))

说明:

(?m)       // enable multi-line matching (^ will act as the start of the line and $ will act as the end of the line (i))
""         // match two successive double quotes
(?!        // start negative look ahead
  [ \t]*   //   zero or more spaces or tabs
  (        //   open group 1
    ,      //     match a comma 
    |      //     OR
    $      //     the end of the line or string
  )        //   close group 1
)          // stop negative look ahead

所以,用简单的英语:匹配两个连续的双引号,只有在他们之前没有逗号或行尾的时候,才可以在之间插入空格和制表符。

So, in plain English: "match two successive double quotes, only if they DON'T have a comma or end-of-the-line ahead of them with optionally spaces and tabs in between".

i)除了是正常的开始字符串结束字符串元字符。

(i) besides being the normal start-of-the-string and end-of-the-string meta characters.

这篇关于在CSV文件中查找未转义的双引号的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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