可视代码:从json文件中删除注释

可视代码:从json文件中删除注释,json,visual-studio-code,Json,Visual Studio Code,我正在使用robo 3t从mongo导出一个巨大的文档集,导出过程如下: /* 1 */ { "key":"value" } /* 2 */ { "key":"value" } ... /* 2456 */ { "key":"value" } 我需要删除所有像/*X*/这样的行,其中X是数字。我在vscode中使用了replace file方法,但我无法放入有效的正则表达式来匹配所有这些行:这就是我在搜索文本框中输入的内容:/*(.*) 提前感谢*是regex中的一个特殊字符,它表示前面的表达

我正在使用robo 3t从mongo导出一个巨大的文档集,导出过程如下:

/* 1 */
{
"key":"value"
}
/* 2 */
{
"key":"value"
}
...
/* 2456 */
{
"key":"value"
}
我需要删除所有像/*X*/这样的行,其中X是数字。我在vscode中使用了replace file方法,但我无法放入有效的正则表达式来匹配所有这些行:这就是我在搜索文本框中输入的内容:
/*(.*)


提前感谢

*
regex
中的一个特殊字符,它表示前面的表达式重复了零次或多次。为了表示自身,需要使用
\
对其进行转义

应该工作的正则表达式是:

^/\*\s*\d*\s*\*/$
解释

^         # match only at the beginning of the line
/         # match a slash (/); the slash is a regular character in regex
\*        # match an asterisk (*); the asterisk needs to be escaped to represent itself
\s*       # match zero or more space characters (\s); these are whitespaces and tabs
\d*       # match zero or more digits (\d)
\s*       # match zero or more space characters
\*        # match '*'
/         # match '/'
$         # match at the end of the line (but not the end of line itself);
如果将此正则表达式用于搜索,将空字符串用于替换,则注释行的内容将被删除,但行本身不会被删除(行由其行尾字符确定)


要完全删除注释行,请在上述正则表达式的末尾添加
\n
\n
匹配行尾字符。

谢谢,我终于设法匹配了/*(.*)

*
regex
中的一个特殊字符,它意味着前面的表达式重复了零次或多次。为了表示自身,需要使用
\
对其进行转义。