擅长:python、mysql、java
<p>您可以使用<code>re.search()</code>(或<code>re.match()</code>-取决于您的需要)并获取捕获组:</p>
<pre><code>>>> import re
>>> s = "RegisterParameter uri wub {"
>>> match = re.search("RegisterParameter uri ([^ ]*) {", s)
>>> match.group(1) if match else "Nothing found"
'wub'
</code></pre>
<p>另外,您可能希望使用<code>\w*</code>,而不是<code>[^ ]*</code>。<code>\w</code>匹配任何单词字符。你知道吗</p>
<p>另请参见:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/180986/what-is-the-difference-between-pythons-re-search-and-re-match">What is the difference between Python's re.search and re.match?</a></li>
<li><a href="https://stackoverflow.com/questions/1576789/in-regex-what-does-w-mean">In regex, what does \w* mean?</a></li>
</ul>