删除$之间的所有内容,包括乳胶文件中的多行
我正在使用laTex文件,我需要删除两个$之间的所有内容,包括换行符,并且只保留英文文本。
我使用这样的命令处理的文件:
find "." -name "*.tex" | xargs perl -pi -e 's/\$[^\$].*?\$/ /g' *
实施例:
Then use the naturality formula
$t_{G^{n-1}M} G^{i+1} (\epsilon_{G^{n-i}M})
= G^{i+1} (\epsilon_{G^{n-i}M}) t_{G^n M}$ on the left-hand side.
输出:
:
Then use the naturality formula
on the left-hand side.
从文件的另一示例例如:
\begin{itemize}
\item $M$ is atomic and finitely generated;
\item $M$ is cancellative;
\item $(M, \le_L)$ and $(M, \le_R)$ are lattices;
\item there exists an element $\Delta \in M$, called {\it Garside element}, such that the set
$L(\Delta)= \{ x \in M; x\le_L \Delta\}$ generates $M$ and is equal to $R(\Delta)= \{ x\in M;
x\le_R \Delta\}$.
\end{itemize}
OUTPUT:
\begin{itemize}
\item is atomic and finitely generated;
\item is cancellative;
\item and are lattices;
\item there exists an element , called {\it Garside element}, such that the set
generates and is equal to $R(\Delta)= \{ x\in M;
x\le_R \Delta\}$.
\end{itemize}
如果你可以看到($ R(\德尔塔)= {在一M×\; x \ le_R \ Delta} $。)不能被删除!
实施例2从不同的文件,则输入相同输出一切都没有改变:
Using the fact that is atomic and that $L(\Delta)=
\{x \in M; x \le_L \Delta\} M \pi_L(a) \neq 1 a \neq
1 k \partial_L^k(a)=1 k$ be the
我猜测这是不匹配时,它应当匹配文本跨越多行。
你有[^\$].*?
其中一个字符不$
使用[^\$]
然后匹配.*?
这不是一个换行符懒洋洋的零次或多次匹配任何字符相匹配。这适用于您的单行案例,因为懒惰修改器试图在另一个.
之前匹配$
,但由于.
与换行符不匹配,所以多行案例失败。
正确和更有效的将是[^\$]*
它将尽可能多地匹配包括换行符在内的非$
字符。
所以你的命令将是
s/\$[^\$]*\$/ /g
或清洁期待在我看来,使用非标准的分隔符,避免 '栅栏柱' 看/\
s~\$[^\$]*\$~ ~g
的Perl一行一行地处理你的文件,这是跨越换行失败的另一个原因。对于这个问题已经有很多文档的答案,并且由知道Perl比我更好的人编写:How to match multiline data in perl
不幸的是它没有工作!比如这个案子还没有解决,..投影$ I_ {d,i} \ rightarrow M_ {d,i} M_ {d,0} $,这里所有的.. – Zain
这个在我的测试中有效。 。 。 https://regex101.com/r/qZvkQ3/2 –
你能否更新你的问题与多个案例不工作的多个例子? –
*“它可以工作,但不适用于我在文件中的所有情况”*请给出一些示例不能正常工作的情况以及要处理的简要示例文档。要求我们在没有看到任何输入的情况下编写软件是不公平的。 – Borodin
我编辑回你的正则表达式/命令作为我相关的信息的问题。我也更新了我的回答 –