<p>也许吧</p>
<pre><code>(?<=[^A-Z]|^)[A-Z]{3}[a-z][A-Z]{3}(?=[^A-Z]|$)
</code></pre>
<p>那就行了。你知道吗</p>
<h3><a href="https://regex101.com/r/QE35Dn/1/" rel="nofollow noreferrer">Demo</a></h3>
<hr/>
<p>我想要实现这个模式,我们可能需要安装<code>regex</code>模块</p>
<pre><code>$ pip3 install regex
</code></pre>
<p>否则,我认为模式<a href="https://stackoverflow.com/a/58827308/6553328">in this answer</a>将是一个更好的选择,您可以使用<code>re</code>模块来实现它:</p>
<pre><code>import re
string = '''
sDdDSADadasAHHdHSAsdsagfGoHHHfHHHH
AHHdHSA
'''
expression = r'(?<![A-Z])[A-Z]{3}[a-z][A-Z]{3}(?![A-Z])'
print(re.findall(expression, string))
</code></pre>
<h3>测试</h3>
<pre><code>import regex as re
string = '''
sDdDSADadasAHHdHSAsdsagfGoHHHfHHHH
AHHdHSA
'''
expression = r'(?<=[^A-Z]|^)[A-Z]{3}[a-z][A-Z]{3}(?=[^A-Z]|$)'
print(re.findall(expression, string))
</code></pre>
<h3>输出</h3>
<pre><code>['AHHdHSA', 'AHHdHSA']
</code></pre>
<hr/>
<p>如果您希望简化/修改/探索表达式,在<a href="https://regex101.com/r/QE35Dn/1/" rel="nofollow noreferrer">regex101.com</a>的右上面板中已经解释过了。如果您愿意,还可以在<a href="https://regex101.com/r/QE35Dn/1/debugger" rel="nofollow noreferrer">this link</a>中查看它与一些示例输入的匹配情况。你知道吗</p>
<hr/>
<h3>正则表达式电路</h3>
<p><a href="https://jex.im/regulex/#!flags=&re=%5E(a%7Cb)*%3F%24" rel="nofollow noreferrer">jex.im</a>可视化正则表达式:</p>
<p><a href="https://i.stack.imgur.com/TjH9I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TjH9I.png" alt="enter image description here"/></a></p>