title: Get substring from a string with specific pattern
body: <p>I am working with twitter links and I have extracted the links from twitter's api.</p>
  <pre><code>https://twitter.com/shiromiru36/status/1302713597521403904/photo/1
  </code></pre>
  <p>The above is an example of links that I have.</p>
  <p>I would like to get front part of the link only, I want to delete</p>
  <pre><code>/photo/1
  </code></pre>
  <p>So that I can get</p>
  <pre><code>https://twitter.com/shiromiru36/status/1302713597521403904
  </code></pre>
  <p>Currently I extract the link by counting the number of words that I don't want</p>
  <pre><code>url = https://twitter.com/shiromiru36/status/1302713597521403904/photo/1
  url[:-8]
  </code></pre>
  <p>I would like to ask if there is any way to extract the link by finding its own pattern. As the unwanted part is after the 2nd last &quot;/&quot;. I am thinking whether I can delete the unwanted part by finding the 2nd last &quot;/&quot; first, and then delete the words after it.</p>
  <p>Thank you.</p>