如何在IntelliJ中替换整行代码,其中行以相同的前缀开头

huangapple go评论63阅读模式
英文:

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

问题

我有几行代码,如下所示

line1
line2
//要删除的注释行。
line3
//要删除的注释行。
//要删除的注释行
line4

在这里,我将使用查找和输入`//`,以便匹配并突出显示所有注释行。

现在如何使用查找和替换来替换(删除)整行。

也就是说,替换文本或正则表达式是什么?

因此,最终输出应为
line1
line2
line3
line4
英文:

i have a few lines of code like

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

here i will use find and input // so all the comment lines will be matched and highlighted.

now how do i repalce (remove) the entire line with the help of find and replace.

i.e what would be the replace text or regular expression.?

so the final output should be

line1
line2
line3
line4

答案1

得分: 0

在查找字段中,输入“//.*\n”(不包括引号)作为正则表达式。
在替换字段中,保持为空。
点击“全部替换”按钮。完成。

英文:

In the find field, input "//.*\n" (exclude the ") as regular expression.
In the replace field, keep empty.
Click "Replace All" button. Done.

答案2

得分: 0

Addition to @Yumin, you can cover both below lines with this regular expression : (//.)|(/\.?\/)

  1. //comment1
  2. /comment2/
英文:

Addition to @Yumin, you can cover both below lines with this regular expression : (//.)|(/\.?\/)

  1. //comment1
  2. /comment2/

huangapple
  • 本文由 发表于 2020年1月3日 16:13:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575157.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定