<p>使用</p>
<pre><code>^.*?/([^/]*)/?$
</code></pre>
<p>见<a href="https://regex101.com/r/xm1tYA/1" rel="nofollow noreferrer">proof</a></p>
<p><strong>解释</strong></p>
<pre><code>--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
/ '/'
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[^/]* any character except: '/' (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
/? '/' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
</code></pre>
<p><a href="https://tio.run/##Hc29DoIwFEDhvU/RNA5gLJeIgw6GxdHN0UjSSKE15bZe7gBPX3/mk3wnrewiNjn7KUViSVaQHe0iz5JUV21bKO4dPLYltBsl2C78LQrYIvoZ3oYNgeGk@@iM3tf1CZwlXJ9OvwzqKeLgw6xHY4O@Ha9TczkEUCKRRy7IVoPH3oRQ/J87@fPLUuT8AQ" rel="nofollow noreferrer">Python code</a>:</p>
<pre class="lang-py prettyprint-override"><code>import re
regex = r"^.*?/([^/]*)/?$"
text = "/tennis/qatar/atp-doha-2009/hernych-jan-monfils-gael-S8Lm3D4l/"
print(re.findall(regex, text))
</code></pre>
<p>结果:<code>['hernych-jan-monfils-gael-S8Lm3D4l']</code></p>