擅长:python、mysql、java
<p>有许多模式可用于解决此问题:</p>
<p>我给你展示了三种模式,你可以选择你想要的:</p>
<blockquote>
<p>first pattern :</p>
</blockquote>
<pre><code>import re
pattern=r'stp\s(\d+)'
output=[]
with open('file.txt','r') as f:
for line in f:
match=re.search(pattern,line)
output.append(match.group(1))
print(output)
</code></pre>
<p>输出:</p>
<pre><code>['11441', '20000']
</code></pre>
<blockquote>
<p>Pattern 2:</p>
</blockquote>
<pre><code>r'[0-9]{5}'
</code></pre>
<blockquote>
<p>pattern 3:</p>
</blockquote>
<pre><code>Positive Lookbehind (?<=stp\s)
pattern=r'(?<=stp\s)\d+'
</code></pre>