Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove comments from text file in Java

Tags:

java

Is there any easy way to remove the comments from the text file in Java.

now:

:-  /* #pos=1,513 */ author(A, UniqueVar1)

after:

author(A, UniqueVar1)

I used BufferedReader and readline to read and split the lines.

like image 427
vikky 2405 Avatar asked Oct 29 '22 09:10

vikky 2405


1 Answers

try this:

line.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)|(?::-)","");
like image 195
data_person Avatar answered Nov 15 '22 04:11

data_person