文字列内のLaTeXコメントを削除しようとしています:
入力文字列:
\begin{comment}内部\nコメント1\end{comment}何か外部コメント\begin{comment}内部コメント2\end{comment}コメント2の後
出力:
\begin{comment}コメント1の内側\end{comment}コメント2の後にコメントの外側の何か
望ましい出力:
something outside comments after comment 2
サンプルコード:
public static void main(String[] args) {
String input = "\\begin{comment}inside \n comment 1 \\end{comment} something outside comments \\begin{comment} inside comment 2\\end{comment} after comment 2";
System.out.println(input.replaceAll("\\\\begin\\{comment\\}(.*|[\\s]*|\\n*)\\\\end\\{comment\\}", ""));
}
したがって、問題は、この正規表現がを検出していないこと\n
です。
次のリンクを使用して正規表現を作成しました。