vim正则表达式匹配内联注释

时间:2023-02-08 21:47:38

Assuming the following sample inline comment:

假设以下示例内联注释:

/*
function newMethodName (int bar, String s) {
   int i = 123;
}
s/\<foo\s*(/newMethodName (/g
*/

How would I match and replace such that it would, essentially, become uncommented. I got this far before giving up.

我将如何匹配和替换,以便它基本上会被取消注释。在放弃之前,我已经走了这么远。

:%s/\/\*\(\_.\)*\*\//\1/

Solution

:%s/\/\*\(\_.*\)\*\//\1/

1 个解决方案

#1


1  

Your capture group ( ) is capturing one character or newline. Put the following * inside so that \1 replacement gets the whole string rather than just the first character.

您的捕获组()正在捕获一个字符或换行符。将以下*置于内部,以便\ 1替换获取整个字符串而不仅仅是第一个字符。

#1


1  

Your capture group ( ) is capturing one character or newline. Put the following * inside so that \1 replacement gets the whole string rather than just the first character.

您的捕获组()正在捕获一个字符或换行符。将以下*置于内部,以便\ 1替换获取整个字符串而不仅仅是第一个字符。