擅长:python、mysql、java
<p>您可以这样尝试:</p>
<pre><code>import re
if __name__=='__main__':
matches = re.findall('(?i)your\s*project\s*is\s*ready\.\s*your\s*id:\s*(.*)', "Your project is ready. Your ID:MixCaseID\nYour project is ready. Your ID:1234566\nYour project is ready. Your ID:lowercaseid\nYour project is ready. Your ID:UPPERCASEID\nYour project is ready. Your ID:PROJ-0001")
for m in matches:
print(m)
</code></pre>
<p>结果:</p>
<pre><code>MixCaseID
1234566
lowercaseid
UPPERCASEID
PROJ-0001
</code></pre>
<p>此处:</p>
<pre><code>(?i) = Case insensitive match
\s* = whitespace zero or more times
</code></pre>
<p>如果你的项目准备好了。不需要您的ID:MixCaseID您可以通过在'Your\s*ID:'之前排除模式来缩短regex。然后它将查找出现在“Your ID:”旁边的ID。你知道吗</p>