2

I wanted to comment out some java code using Notepad++ e.g.

StringBuffer sbTest = new StringBuffer();
sbTest.append("aaa");
sbTest.append("bbb");
sbTest.append("ccc");
sbTest.append("aaa");
sbTest.append("ddd");

Lets say I want to comment out all lines containing "aaa" How to do that in Notepad++ I know a procedure to bookmark the lines containing this text but how to comment out these bookmarked lines I am not sure. Can you please suggest some way I can do this using Notepad++?

2 Answers 2

2

Using Regular Expression find and replace search for (.*"aaa") and replace that with //\1.

  • "aaa" is what you are searching for and .* means you pickup characters before that on the line and the brackets create a group of all the characters searched for.
  • \1 then inserts the group into the replacement.
3
  • Hi, it replaces the line by comment. I need to add // in front of every line which contains "aaa" but if I try your solution I can find the line but when I add "\1//" in to replace it replaces the line by //);
    – Amol Patil
    Jul 24, 2015 at 4:31
  • I think the problem is that you are missing out the \1 from the replacement string. That is important as it selects the first group. That or you didn't include the brackets around the find term.
    – meh-uk
    Jul 24, 2015 at 9:08
  • @AmolRamkrishnaPatil have I answered your question or haven't you had time to look yet?
    – meh-uk
    Jul 30, 2015 at 14:21
3

Using 'find and replace' in regular expression mode:

  • Find what: (.*aaa)
  • Replace with: //\1
  • Click on 'Replace All'

enter image description here

enter image description here

1
  • Hi Thanks for the solution. meh-uk has provided correct answer first hence I have selected it as accepted answer but you definitely make it more clear.. hence +1
    – Amol Patil
    Sep 4, 2015 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .