Text 如何剥离所有引号并使用记事本重新添加文本选项卡分隔的文件++;

Text 如何剥离所有引号并使用记事本重新添加文本选项卡分隔的文件++;,text,replace,notepad++,delimited-text,delimited,Text,Replace,Notepad++,Delimited Text,Delimited,我需要在SQL Server中导入一些相当脏的文本选项卡数据。它失败是因为其中一个列分隔符出现了问题。这是因为某些列中出现了双引号。我正在努力纠正这一点,我的理论是删除所有引号,然后用正则表达式将每个制表符分隔的字段再次用单引号括起来。尽管搜索了很多类似的帖子,我还是找不到一个有效的答案,有人能帮忙吗 它不一定是记事本+,但它是我最熟悉的 "REDACTED" "REDACTED" REDACTED "REDACTED" "REDACTED" "REDACTED" ""

我需要在SQL Server中导入一些相当脏的文本选项卡数据。它失败是因为其中一个列分隔符出现了问题。这是因为某些列中出现了双引号。我正在努力纠正这一点,我的理论是删除所有引号,然后用正则表达式将每个制表符分隔的字段再次用单引号括起来。尽管搜索了很多类似的帖子,我还是找不到一个有效的答案,有人能帮忙吗

它不一定是记事本+,但它是我最熟悉的

    "REDACTED"  "REDACTED"  REDACTED    "REDACTED"  "REDACTED"  "REDACTED"  ""  "REDACTED"    "REDACTED"    "REDACTED"  ""Problematic, field""  ""  ""  ""  "REDACTED"  "REDACTED"  "REDACTED"  ".00"   "805400838" 94.17   22.77   4.13    ".83"   117.95  220 2   0   "REDACTED"

如果您的要求没有进一步解释,我想您应该删除所有双引号,并在每个字段周围添加单引号

这就是工作:

  • Ctrl+H
  • 查找内容:
    (?
    
  • 替换为:
    (?1'$1':'$3')
  • 检查环绕
  • 检查正则表达式
  • 全部替换
说明:

  (?<=\s)           # positive lookbehind, make sure we have a space before
  ""                # 2 double quote
  (?=\s|$)          # positive lookahead, make sure we have aspace after or end of line
|               # OR
  (?<=\s)           # positive lookbehind, make sure we have a space before
  ([^"\s]+)         # group 1, 1 or more any characte that is not space or double quote
|               # OR
  (?<!")            # negative lookbehind, make sure we haven't a double quote before
  ("+)              # group 2, 1 or more double quote
  ([^"]+)           # group 3, 1 or more non double quote
  \2                # reference to group 2, same number of double quote
(?1             # conditional replacement, if group 1 exists
  '$1'              # content of group 1 surrounded with single quotes
 :              # else
  '$3'              # content of group 3 surrounded with single quotes
)               # end condition
屏幕截图(之前):

  (?<=\s)           # positive lookbehind, make sure we have a space before
  ""                # 2 double quote
  (?=\s|$)          # positive lookahead, make sure we have aspace after or end of line
|               # OR
  (?<=\s)           # positive lookbehind, make sure we have a space before
  ([^"\s]+)         # group 1, 1 or more any characte that is not space or double quote
|               # OR
  (?<!")            # negative lookbehind, make sure we haven't a double quote before
  ("+)              # group 2, 1 or more double quote
  ([^"]+)           # group 3, 1 or more non double quote
  \2                # reference to group 2, same number of double quote
(?1             # conditional replacement, if group 1 exists
  '$1'              # content of group 1 surrounded with single quotes
 :              # else
  '$3'              # content of group 3 surrounded with single quotes
)               # end condition

屏幕截图(之后):

  (?<=\s)           # positive lookbehind, make sure we have a space before
  ""                # 2 double quote
  (?=\s|$)          # positive lookahead, make sure we have aspace after or end of line
|               # OR
  (?<=\s)           # positive lookbehind, make sure we have a space before
  ([^"\s]+)         # group 1, 1 or more any characte that is not space or double quote
|               # OR
  (?<!")            # negative lookbehind, make sure we haven't a double quote before
  ("+)              # group 2, 1 or more double quote
  ([^"]+)           # group 3, 1 or more non double quote
  \2                # reference to group 2, same number of double quote
(?1             # conditional replacement, if group 1 exists
  '$1'              # content of group 1 surrounded with single quotes
 :              # else
  '$3'              # content of group 3 surrounded with single quotes
)               # end condition

预期结果是什么?每个字符串都必须用单引号括起来,即使它是空的。我编辑了我的帖子,因此在示例中,您可以看到字段周围出现了双引号,这可能是由于供应商使用了“作为一种转义。如果一个值或日期最后用引号括起来,这并不是世界末日,因为我可以修复导入后的问题。那么,您想用单引号替换所有双引号,那么空格或不带引号的单词呢?我不清楚,请简化一下示例并添加预期结果。