我试图删除一堆评论,这些评论的格式如下:
/**
* @ngdoc
... comment body (delete me, too!)
*/我尝试使用以下命令:%s/\/**\n * @ngdoc.\{-}*\///g
下面是没有模式的正则表达式:%s/pattern1.\{-}pattern2//g
下面是单独的模式:\/**\n * @ngdoc和*\/
当我在vim中尝试我的模式时,我得到以下错误:
E871: (NFA regexp) Can't have a multi follow a multi !
E61: Nested *
E476: Invalid command谢谢你帮忙做这场雷杰普噩梦!
发布于 2017-08-24 05:02:37
与其尝试将其插入一个复杂的regex中,更容易的是搜索注释的开头并从注释中删除到注释的末尾
:g/^\/\*\*$/,/\*\/$/d_这会分解成
:g start a global command
/^\/\*\*$/ search for start of a comment: <sol>/**<eol>
,/^\*\/$/ extend the range to the end of a comment: <sol>*/<eol>
d delete the range
_ use the black hole register (performance optimization)发布于 2017-08-23 23:03:16
您的问题是,您有\{-}和*,这是错误消息中引用的multis。引用*
%s/\/\*\*\n \* @ngdoc\_.\{-}\*\/\n//g发布于 2017-08-23 23:30:12
在模式中使用嵌入的换行符是错误的方法。您应该使用一个地址范围。类似于:
sed '\@^/\*\*$@,\@^\*/$@d' file这将删除从与锚定在第1列的/**匹配的行开始到与第1列锚定的*/匹配的行。如果您的注释行为良好(例如,在/**之后没有尾随空间),这应该可以做您想做的事情。
https://stackoverflow.com/questions/45850515
复制相似问题