【发布时间】:2012-08-16 08:17:01
【问题描述】:
我正在尝试删除字符串中的 LaTeX cmets:
输入字符串:
\begin{comment}inside \n comment 1 \end{comment} cmets 之外的东西 \begin{comment} inside comment 2 \end{comment} 在评论 2 之后
输出:
\begin{comment}inside comment 1 \end{comment} 在评论 2 之后在 cmets 之外的东西
理想的输出:
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。
我使用以下链接来形成正则表达式:
【问题讨论】:
标签: java regex latex newline replaceall