2
我需要在字符串中找到所有多行註釋,並用空格(如果註釋在一行中)或\n
(如果註釋位於多行)替換它們。 例如:如何使用正則表達式抑制單行和多行註釋?
int/* one line comment */a;
應改爲:
int a;
這:
int/*
more
than one
line comment*/a;
應改爲:
int
a;
我有一個字符串所有的文字和我使用這個命令:
file = file.replaceAll("(/\\*([^*]|(\\*+[^*/]))*\\*+/)"," ");
其中file是字符串。
問題是它找到了所有多行註釋,我想將它分開爲2個案例。 我該怎麼辦?