2017-06-04 55 views
0

我有一個6200百頁預訂簡單的東西,如:正則表達式來刪除所有 {開始收集} {結束}聚集

\begin{gather} 
    A>B,A=B,A<B,A\leq B,A \geq B 
\end{gather} 

或更多的複雜化:

\begin{gather} 
    \begin{aligned} 
    (a+b)^0&=1\\ 
    (a+b)^1&=1a+1b\\ 
    (a+b)^2&=1a^2+2ab+1b^2\\ 
    (a+b)^3&=1a^3+3a^2b+3ab^2+1b^3\\ 
    \end{aligned} 
\end{gather} 

我試圖找到RegEx刪除所有\ begin {gather} \ end {gather}環境(它是LaTeX)。我已經通過試驗和錯誤找到的最好的是:

(\\begin\{gather\}*\r?\n?.*)*\r?\n?.*(\r?\n?.*\\end\{gather\}) 

但它不工作: - (((

任何幫助將提前欣賞

THX

+1

嘗試'(?S)\\開始\ {}聚集。*?\\結束\ {收集}' –

+0

都能跟得上!至少在Notepad ++ 7.4.1中,我使用它似乎不起作用...: - (( –

+0

你是什麼意思,「它似乎不工作」?你究竟在做什麼?你需要實際轉義'}' :'(?s)\\ begin \ {gather \}。*?\ end \ {gather \}'(這是我在頂端評論中遺漏的Boost正則表達式細節) - 它將匹配有問題的塊。然後,只需要替換一個空的空間,對吧? –

回答

0

。這工作在記事本+ +:

(?s)\\begin\{gather\}.*?\\end\{gather\} 

請確保您設置選項(。matches newline)

下面是使用ungreedy選項「。*?」和「(?s)」修飾符:單行的Regex101示例。點匹配換行符。

example

+0

謝謝,但...如果你採取這個MWE(最小的工作克實施例): '唧唧歪歪: \開始{收集} A> B,A = B,A