<p><a href="http://docs.python.org/2/library/re.html#re.match" rel="nofollow">^{<cd1>}</a>不直接支持这一点。但是,如果使用<a href="http://docs.python.org/2/library/re.html#re.compile" rel="nofollow">^{<cd2>}</a>预编译正则表达式(通常是个好主意),那么<a href="http://docs.python.org/2/library/re.html#re.RegexObject" rel="nofollow">^{<cd3>}</a>的类似方法<a href="http://docs.python.org/2/library/re.html#re.RegexObject.match" rel="nofollow">^{<cd4>}</a>(和<a href="http://docs.python.org/2/library/re.html#re.RegexObject.search" rel="nofollow">^{<cd5>}</a>)都采用可选的<em>pos</em>参数:</p>
<blockquote>
<p>The optional second parameter <em>pos</em> gives an index in the string where the search is to start; it defaults to <code>0</code>. This is not completely equivalent to slicing the string; the <code>'^'</code> pattern character matches at the real beginning of the string and at positions just after a newline, but not necessarily at the index where the search is to start.</p>
</blockquote>
<p>示例:</p>
<pre><code>import re
s = 'this is a test 4242 did you get it'
pat = re.compile('[a-zA-Z]+ ([0-9]+)')
print pat.match(s, 10).group(0)
</code></pre>
<p>输出:</p>
<pre><code>'test 4242'
</code></pre>