How may I apply double quotes around every value of csv file using TextMate?

左心房为你撑大大i 提交于 2019-12-06 01:34:14

问题


I have a csv file with the following format:

example csv:

bear,brown,mean,large
ant,black,strong,tiny
cat,yellow,moody,small

How may I apply double quotes around every value? How may I accomplish this using regex?

I am using TextMate (text editor) to do the find/replace w/ regular expression.


回答1:


Here are the important portions of the regex. Hopefully I got it right when I converted to textmate format:

Search - ([^,]*)(,|$)

Replace - "$1"$2

Search explanation: Find every character that is not a comma, up until we reach a comma, or the end of the line. Capture the match for string to be quoted in one variable, and capture the comma/end-of-line match in another variable.

Replace explanation: The original string, quoted, and the comma or end-of-line that follows it.




回答2:


You could start with:

find: ,
replace: "," 

then add a " at the start and at the end?




回答3:


This worked great for me. Did the find/replace for rows first

Then did the simple find / replace for , => ","

Had to add the first quote, and adding the "Markup" made it easy.

Thanks and good luck.



来源:https://stackoverflow.com/questions/3560083/how-may-i-apply-double-quotes-around-every-value-of-csv-file-using-textmate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!