如何替换 intellij 中的整行代码,其中行以公共前缀开头

How to replace an entire line of code in intellij , where lines start with a common prefix

我有几行代码像

line1
line2
//a comment line to be removed.
line3
//a comment line to be removed.
//a comment line to be removed
line4

这里我将使用查找和输入 // 这样所有的注释行都将被匹配并突出显示。

现在我如何在查找和替换的帮助下重新替换(删除)整行。

即替换文本或正则表达式是什么?

所以最终输出应该是

line1
line2
line3
line4

在查找字段中,输入“//.*\n”(不包括“)作为正则表达式。 在替换字段中,保留为空。 单击 "Replace All" 按钮。完成。

除了@Yumin,你可以用这个正则表达式覆盖下面两行:(//.)|(/\.?\/)

  1. //评论1
  2. /评论2/