查找 CSV 文件中双引号引起的列中包含的 2 个未转义双引号的集合的正则表达式是什么?
不匹配:
"asdf","asdf"
"", "asdf"
"asdf", ""
"adsf", "", "asdf"
Run Code Online (Sandbox Code Playgroud)
匹配:
"asdf""asdf", "asdf"
"asdf", """asdf"""
"asdf", """"
Run Code Online (Sandbox Code Playgroud)
尝试这个:
(?m)""(?![ \t]*(,|$))
Run Code Online (Sandbox Code Playgroud)
解释:
(?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
Run Code Online (Sandbox Code Playgroud)
因此,用简单的英语来说:“匹配两个连续的双引号,前提是它们前面没有逗号或行尾,并且之间可以选择空格和制表符”。
(i) 除了正常的字符串开头和字符串结尾元字符之外。