regex - Remove comments from a java file and maintain file structure -
i working on project requires me remove comments java file. currently, using regular expression
(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)
which got http://ostermiller.org/findcomment.html.
the regular expression works well, problem need preserve file structure when remove comments. in other words, if have 3 line block comment, need replaced 3 blank lines. necessary code remains on same line numbers original.
how replace 3 line block comment 3 blank lines?
edit: able solve problem making use of sablecc.
i haven't sussed out regex doing, if matches entire comment, can matched comment, check see how many newlines contains, , replace match many newlines instead of replacing empty string.
Comments
Post a Comment