Remove comments from a text file in Java

Is there an easy way to remove comments from a text file in Java.

now:

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

after:

author(A, UniqueVar1)

I used BufferedReader and readline to read and split lines.

+4
source share
1 answer

try the following:

line.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)|(?::-)","");
+2
source

Source: https://habr.com/ru/post/1673681/


All Articles