嗨,我正在尝试删除一串多行/*
之间的所有代码。*/
到目前为止我有这个:
Scanner scan = new Scanner(inputFile).useDelimiter("\\Z");
String file = scan.next();
String next = file.replaceAll("((/\\*)(\\s|\\S)*(\\*/))", "");
但是,当我尝试使用具有多种情况的输入文件运行它时/*
,*/
它会删除它们之间的所有内容。例如,在这个输入
/* first comment */
a = b;
//test
if a = c;
// whatever
if a = d;
/* this
is a
test
*/
/* another */
它将删除文件末尾第一个/*
和最后一个之间的所有内容。*/
基本上用空格替换整个文本。如何将其限制为/**
and的第一种情况**/
?