擅长:python、mysql、java
<pre><code>import re
text = """United Nations & Headquarters
United <br> Nations Headquarters
United Natio<b>ns Hea</b>dquarters"""
s = "United Nations Headquarters"
r = re.compile(".*?".join(s))
print([v.span() for v in r.finditer(text)])
</code></pre>
<p>关键是<code>".*?".join(s)</code>,它在<code>s</code>的每对连续字符之间插入{<cd2>},将其转换为正则表达式。在</p>
<p>如果您想限制允许的中断,您可能更愿意将<code>.*?</code>收紧一点。在</p>