擅长:python、mysql、java
<p>默认情况下,<code>*</code>是贪婪的,这意味着它试图使用尽可能多的字符。如果希望匹配尽可能少的<em>字符,可以使用非贪婪限定符<code>*?</code>:</p>
<pre><code>print(re.findall(r'data-rlocation="(.*?)"',contents))
</code></pre>
<p>更多信息:<a href="https://docs.python.org/3.5/howto/regex.html#greedy-versus-non-greedy" rel="nofollow noreferrer">https://docs.python.org/3.5/howto/regex.html#greedy-versus-non-greedy</a></p>