擅长:python、mysql、java
<p>我怀疑你在找<a href="https://docs.python.org/2/library/re.html" rel="nofollow noreferrer"><strong>^{<cd1>}</strong></a>。</p>
<p>见<a href="http://ideone.com/EVVEy5" rel="nofollow noreferrer">this demo</a>:</p>
<pre><code>import re
my_regex = re.compile(r'\[([^][]+)\]')
print(my_regex.findall('[xy][abc]'))
['xy', 'abc']
</code></pre>
<p>如果您想遍历匹配项而不是匹配字符串,可以改为查看<a href="https://docs.python.org/2/library/re.html#re.finditer" rel="nofollow noreferrer">^{<cd2>}</a>。有关详细信息,请参见<a href="http://docs.python.org/library/re.html" rel="nofollow noreferrer"><strong>Python ^{<cd3>} docs</strong></a>。</p>