擅长:python、mysql、java
<p>您可以这样做:</p>
<pre class="lang-py prettyprint-override"><code>s = "/tennis/qatar/atp-doha-2009/hernych-jan-monfils-gael-S8Lm3D4l/"
s = "/".join(s.split("/")[-2:]) # Equivalent to your regex, with replace
s = s.rstrip("/") # to remove the last slash
</code></pre>