擅长:python、mysql、java
<p>看看相关的问题:<a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?rq=1">you shouldn't parse HTML with regex</a>。改用regex解析器。对于Python,我听说<a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow noreferrer">Beautiful Soup</a>是一条路。</p>
<p>无论如何,如果您想使用regex,您需要确保<code>.*</code>不能经过另一个<code><br></code>。为此,在使用每个字符之前,我们可以使用<a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow noreferrer">lookahead</a>来确保它不会启动另一个<code><br></code>:</p>
<pre><code><br>(?:(?!<br>).)*<br>\s*$
</code></pre>