
[英]How can I convert '+' character to a regular expression for REGEXMATCH in Google Sheets?
[英]Regular Expression: How can I convert CSV data to JSON array?
如何使用正则表达式将csv字符串转换为JSON数组?
我正在尝试将正则表达式与Vim或Sublime Text等文本编辑器一起使用,而不是与编程语言一起使用。 仅供参考,Sublime Text使用Boost语法 。
如果我有一组这样的csv字符串:
"tag1, tag2, tag3"
上面的字符串应采用以下格式:
["tag1", "tag2", "tag3"]
(添加的全部内容的说明...)
csv字符串位于内容的中间,如下所示:
...
{"url":"http://osxdaily.com/2007/0ge5/02/quickly-encrypt-a-file-with-openssl",
"user":"user01","tag_string":"openssl,encrypt",
"created_at":"2011/04/19 05:49:26 +0000",
"title":"Quickly encrypt a file with OpenSSL"},
{"url":"http://staticimport.blogspot.com","user":"user02",
"tag_string":"command,line,developer,tools,osx",
"created_at":"2011/04/19 05:42:13 +0000","title":"Mac OS X Lion Command Line Developer Tools staticimport"},
{"url":"https://developer.apple.com/downloads/index.action",
"user":"user_01","tag_string":"ios,development,download",
"created_at":"2011/04/19 04:47:26 +0000","title":"Apple Developer Download Center"}
...
tag_string是要转换为JSON数组的csv字符串。
在Vim中,分为三步:
:s/,\s*/", "/g
:s/^/[
:s/$/]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.