在Ace编辑器中多行正则表达式搜索和替换

时间:2019-07-29 05:03:07

标签: regex angular ace-editor

是否有关于多行正则表达式搜索的支持文档,并取代了对ace编辑器的支持。

用于多行搜索的正则表达式

\\begin{.+?}(.*\n.*)*?\\end{(.+?)}

我要搜索的乳胶文档内容是:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{fsdfds}
\author{yadu.rvt }
\date{July 2019}

\usepackage{natbib}
\usepackage{graphicx}

\begin{document}

\maketitle

\section{Introduction}
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened.

\begin{figure}[h!]
\centering
\includegraphics[scale=1.7]{universe}
\caption{The Universe}
\label{fig:universe}
\end{figure}

\section{Conclusion}
``I always thought something was fundamentally wrong with the universe'' \citep{adams1995hitchhiker}

\bibliographystyle{plain}
\bibliography{references}
\end{document}

\ n不适用于ace编辑器中的正则表达式搜索。我需要在ace编辑器中启用多行正则表达式搜索。请帮忙。已检查并在https://regex101.com/

中工作

1 个答案:

答案 0 :(得分:0)

这是一个常规的正则表达式模式,即使您的编辑器不支持点全模式,该模式也应该起作用:

\\begin\{([^}]+)\}[\s\S]*?\\end\{\1\}

这里的想法是匹配一个\begin标记,还匹配捕获标记的类型(例如documentfigure)。然后,我们跨换行符进行匹配,直到达到第一个结束的\end标记为止。

Demo

如果我们想使模式更具体,例如,仅匹配单个figure部分,则可以尝试:

\\begin\{figure\}[\s\S]*?\\end\{figure\}

Demo