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

StringBuffer sbTest = new StringBuffer();

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++?


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.
  • 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 Ramkrishna Patil Jul 24 '15 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 '15 at 9:08
  • @AmolRamkrishnaPatil have I answered your question or haven't you had time to look yet? – meh-uk Jul 30 '15 at 14:21

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

  • 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 Ramkrishna Patil Sep 4 '15 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.