| Refresh | Home EGTry.com

remove comments from java source code


input.txt

/**
this is comment
*/

public class ClassName {
 /* hello */
 //single line
  private String name="this is a \"string\".  /*comment*/";  /** same line */ private String title="this is the title";


  public ClassName() //this is the constructor
  {
    
  }
}



output


public class ClassName {
 
 
  private String name="this is a \"string\".  /*comment*/";   private String title="this is the title";


  public ClassName() 
  {
    
  }
}



comment.flex

%%

%line
%char
%standalone

STRING_BODY=(\\\"|[^\n\r\"])*
%%

"/*" ~ "*/" {}

"//" .*$ {}

\"{STRING_BODY}\" {System.out.print(yytext());}