擅长:python、mysql、java
<pre><code>(?<=\$).+(?=\$)
</code></pre>
<p>通过使用lookaround regex,我们可以匹配<code>$ ... $</code>中的所有内容</p>
<pre class="lang-py prettyprint-override"><code>import re
s = "In $ \mathcal{N}=4$ we fix them completely through the duality to null"
regex = re.compile(r'(?<=\$).+(?=\$)', re.M)
# returns you the string containing
# only the contents inside $ ... $
s = ' '.join(map(str.strip, regex.findall(s)))
print(s)
</code></pre>
<p>了解有关lookaround运算符<a href="https://www.regular-expressions.info/lookaround.html" rel="nofollow noreferrer">here</a>的详细信息</p>