正则表达式 – Powershell脚本从CSV中删除双引号,除非双引号内存
我有以下文件格式的.csv:
In: "bob","1234 Main St,New York,NY","cool guy" 我想删除里面没有逗号的双引号: Out: bob,Ny",cool guy 有没有办法在Powershell中做到这一点? 我检查过: > How to remove double quotes on specific column from CSV file using Powershell script
调整
“How to remove double quotes on specific column from CSV file using Powershell script”的代码:
$csv = 'C:pathtoyour.csv' (Get-Content $csv) -replace '(?m)"([^,]*?)"(?=,|$)','$1' | Set-Content $csv 正则表达式(?m)“([^,] *?)”(?=,| $)匹配逗号或行尾之前的任何“0或更多非逗号”(以正面预测和多线选项(?m)强制$匹配换行符,而不仅仅是字符串的结尾. 见regex demo (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |