2021-05-07 19:08:12
怎么用python过滤掉JS文件中的所有注释
txt中的注释有// 或者/**/,过滤代码如下:
BufferedReader reader = new BufferedReader(new FileReader("test.txt"));
PrintStream writer = new PrintStream(new FileOutputStream("test_new.txt"));
String buf;
while ((buf=reader.readLine()) != null) {
if (buf.isEmpty()) {continue;}
if (buf.matches("[/]+.*")) {
buf = buf.replaceAll("[/]+(.*)", "$1"); //去掉前面的/
}
buf = buf.replaceAll("\\s+(.*)", $1); //去掉前面的空格