擅长:python、mysql、java
<p>在regex下面试试,<a href="https://regex101.com/r/ZyYmUi/4" rel="nofollow noreferrer">demo</a>在这里。你知道吗</p>
<pre><code>import re
s = "case 3: -p 8080 %M %a %x %y some_variable another_one %_capture_this %and_this %this%no neither%this %e"
re.findall(r'(?<=\s)\%\w+(?=\s|$)', s)
</code></pre>
<p>输出</p>
<pre><code>['%M', '%a', '%x', '%y', '%_capture_this', '%and_this', '%e']
</code></pre>