0az
0az

Reputation: 360

In Eclipse use find/replace to comment multiline statements

While debugging code, I added a bunch of lines in the form of

System.out.println("DEBUG: (Some statement)");
System.out.println("DEBUG: (Some statement)" + (Some expression));
System.out.println("DEBUG: (Some statement)" + (Some expression) + "Some other text");
System.out.println("DEBUG: (Some statement)" 
    + (Some expression)
    + "(Some other statement)");
System.out
    .println("DEBUG: (Some statement)" 
        + (Some expression)
        + "(Some other statement)");

where (Some expression) and (some statement) are expressions and statements respectively.

Now that I'm done debugging the code, I would like to be able to comment it out using find and replace, and to uncomment it later, if more bugs appear.

I have a regex that works for the single-line statements. (System.out.println("DEBUG:[^,]+"\n)

Is there a regex that works for the multiline statements?

Upvotes: 1

Views: 741

Answers (1)

Chandrayya G K
Chandrayya G K

Reputation: 8849

I suggest go for this solution. Check this post.

Any way regular expression as you asked:

Commenting

Find string: (?m)(?s)(System[\W.]*?out[\W.]*print[\w]*\(\"DEBUG:(.*?);)

Replace string: /*\1*/

Un commenting

Find string:

(?m)(?s)/\*((?m)(?s)(System[\W.]*?out[\W.]*print[\w]*\(\"DEBUG:(.*?);))\*/

Replace string: \1

Refer meta character

Upvotes: 1

Related Questions