<p>因为您已经用<code>#python</code>和<code>#regex</code>标记了您的问题,所以我将使用这些工具概述您的问题的简单解决方案。此外,另外两个答案并没有真正解决匹配<code>"Flow Control "</code>前缀的<em>“右边的任何东西”</em>的确切问题</p>
<ol>
<li>首先,从导入<code>re</code>内置模块(<a href="https://docs.python.org/3/library/re.html" rel="nofollow noreferrer">read the docs</a>)开始</李>
</ol>
<pre class="lang-py prettyprint-override"><code>import re
</code></pre>
<ol start=“2”>
<li>定义要匹配的模式。在这里,我们匹配的是<code>^Flow Control </code>的<em>“右边的任何东西”</em>(<code>(?P<suffix>.+)$</code>)</李>
</ol>
<pre class="lang-py prettyprint-override"><code>pattern = re.compile(r"^Flow Control (?P<suffix>.+)$")
</code></pre>
<ol start=“3”>
<li>获取给定字符串的匹配项(例如<code>"Flow Control None"</code>)</li>
</ol>
<pre class="lang-py prettyprint-override"><code>suffix = pattern.search("Flow Control None").group("suffix")
print(suffix) # Out: None
</code></pre>
<hr/>
<p>希望这个完整的工作示例也能帮助您</p>
<pre class="lang-py prettyprint-override"><code>import re
def get_suffix(text: str):
pattern = re.compile(r"^Flow Control (?P<suffix>.+)$")
matches = pattern.search(text)
return matches.group("suffix") if matches else None
examples = [
"Flow Control None",
"Flow Control None None",
"Flow Control None",
"Flow Control ",
]
for example in examples:
suffix = get_suffix(text=example)
if suffix:
print(f"Matched: {repr(suffix)}")
else:
print(f"No matches for: {repr(example)}")
</code></pre>