如何使用 TextMate 对 csv 文件的每个值应用双引号?
我有一个 csv 文件,格式如下:
示例 csv:
熊,棕色,平均,大 蚂蚁,黑色,强大,微小 猫,黄色,喜怒无常,小
如何在每个值周围应用双引号?我如何使用正则表达式来完成此任务?
我正在使用 TextMate(文本编辑器)使用正则表达式进行查找/替换。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是正则表达式的重要部分。希望当我转换为文本格式时我得到了正确的结果:
搜索 -
([^,]*)(,|$)
替换 -
"$1"$2
搜索说明:查找不是逗号的每个字符,直到我们到达逗号或行尾。捕获一个变量中要引用的字符串的匹配,并捕获另一个变量中的逗号/行尾匹配。
替换说明:带引号的原始字符串及其后面的逗号或行尾。
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.
您可以从以下开始:
然后在开头和结尾添加“?
You could start with:
then add a " at the start and at the end?
这对我来说非常有用。是否首先查找/替换行
然后对 , => 进行简单的查找/替换“,”
必须添加第一个引号,并且添加“标记”使其变得容易。
谢谢,祝你好运。
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.