regex - 除非双引号内存在逗号,否则从 CSV 中删除双引号的 Powershell 脚本

标签 regex powershell csv

最佳答案

改编来自 "How to remove double quotes on specific column from CSV file using Powershell script" 的代码:

$csv = 'C:\path\to\your.csv'
(Get-Content $csv) -replace '(?m)"([^,]*?)"(?=,|$)', '$1' |
    Set-Content $csv

正则表达式 (?m)"([^,]*?)"(?=,|$)匹配任何 " + 0 or more non-commas + "在逗号或行尾之前(通过正向预测和多行选项 (?m) 实现,强制 $ 匹配换行符,而不仅仅是字符串的结尾)。

regex demo

关于regex - 除非双引号内存在逗号,否则从 CSV 中删除双引号的 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30247002/

相关文章:

javascript - 如何在 JavaScript 正则表达式中捕获任意数量的组?

sql - 正则表达式匹配具有多行和相同列数的 SQL 值字符串

powershell - 将控制台输出写入文件 - 文件意外为空

python - 使用 python 将数据文件从源工作表转换为目标工作表格式。

excel - Google 文档导出带双引号的 CSV

javascript - 城市 FR 格式化箱

java - 这个正则表达式匹配什么?

powershell - Roslyn安装-Powershell脚本

powershell - Azure Powershell 命令中的事务

xml - 导出到 Excel - 中间文件格式?