擅长:python、mysql、java
<p>您需要以下正则表达式:</p>
<pre><code>(?s)(Te pri.*?)HELLO WORLD
</code></pre>
<p>分解一下,这个短语的意思是:</p>
<pre><code>(?s) Make the '.' regex metacharacter match newlines too
( Start a capturing group
Te pri Match exactly 'Te pri'
. The dot metacharacter matches any character except newlines
* Match the prior metacharacter, character class or group zero or more times
By default will match as many times as possible
? When paired with '*', it makes '*' match as few times as possible
This way, '.*' doesn't match 'HELLO WORLD'
) End the capturing group
</code></pre>
<p>使用<code>.group()</code>例如访问组中捕获的内容</p>
<pre><code>import re
regex = re.compile(r"(?s)(Te pri.*?)HELLO WORLD")
m = regex.match(your_text)
m.group(1)
</code></pre>
<p>快乐的编码!你知道吗</p>