擅长:python、mysql、java
<pre><code>re.search(r"#(\d+)", ackCount).group(1)
</code></pre>
<p>这将在<code>ackCount</code>字符串中搜索第一个出现的八进制('#'),后跟一个或多个(<code>+</code>)数字(<code>\d</code>),仅捕获由<code>re.search()</code>返回的<code>Match</code>对象的捕获组(<code>.group(1)</code>)中的数字</p>
<p>就你的问题而言,这将成为:</p>
<pre><code>ackCount = "Acknowledgement of #2352 on component \"lOrA-1\""
try:
OAC = int(re.search(r"#(\d+)", ackCount).group(1))
print(OAC)
# error handling if the cast to `int` fails, or there is no returned match
except ValueError, AttributeError:
print("No match found.")
</code></pre>
<pre><code>>>> 2352
</code></pre>