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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -