Win a copy of Barcodes with iOS this week in the iOS forum or Core Java for the Impatient in the Java 8 forum!
Srikanth Madasu wrote:
I am writing a program to delete all the comments from a given java file.
I was able to remove the single line comments using pattern - Pattern p= Pattern.compile("//(.)*");
But matching multiline comments is getting trickier.
I am using - Pattern p= Pattern.compile("/\\*.*\\*/", Pattern.DOTALL); - Basically match anything between /* and */ and include new lines.
But If I have something like below, it is matching this entire thing as a single match and I am losing the code between the comments.
Could some one help me how to rewrite this pattern so that I dont delete the code between the comments?