擅长:python、mysql、java
<p><a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454"><strong>Do not use regular expressions to parse HTML.</strong></a></p>
<p>但是,如果需要在字符串中查找所有regexp匹配项,请使用<a href="http://docs.python.org/library/re.html#re.findall" rel="noreferrer">^{<cd1>}</a>函数。</p>
<pre><code>import re
line = 'bla bla bla<form>Form 1</form> some text...<form>Form 2</form> more text?'
matches = re.findall('<form>(.*?)</form>', line, re.DOTALL)
print(matches)
# Output: ['Form 1', 'Form 2']
</code></pre>