擅长:python、mysql、java
<p>试试这个<a href="https://regex101.com/r/mrVK7Z/2/" rel="nofollow noreferrer">regex-demo</a>:</p>
<p><strong>python源代码:</strong></p>
<pre><code>input="""DD-JSH-String43423213-3774
DE-String43423214-SDC-3721"""
</code></pre>
<pre><code>matches = re.findall(r'String\d+', input, flags=re.I)
print(matches)
</code></pre>
<p>或</p>
<pre><code>matches = re.findall(r'(?i)String\d+', input)
print(matches)
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>['String43423213', 'String43423214']
</code></pre>
<p><strong>说明:</strong>
由于正则表达式有两个组<code>String</code>和<code>\d+</code>,<strong>re.findall</strong>返回一个列表,其中包含两个组的所有元组,如<code>('String', 'String43423214')</code>。您可以像<code>(String\d+)</code>或像<code>String\d+</code>一样对它进行分组,这两个表达式都有效</p>