title: Regex to extract substring between different starting and ending strings within HTML
body: <p>I am trying to write a simple scraper tool that will extract a specific URL from a webpage. The page has many URLs, but I want to get the one that ends with a specific set of characters.</p>
  
  <p>For example, if somewhere in the page source there is a url that looks like this:</p>
  
  <p><code>source: "https://www.website.com/dog.pdf"</code></p>
  
  <p>I want to return <code>https://www.website.com/dog.pdf</code> without the quotes. If there is more than one match, I only want to return the first one.</p>
  
  <p>So the Regex should extract everything after <code>source:</code> and up to and including the <code>.pdf"</code></p>
  
  <p>--</p>
  
  <p>I've looked at other questions, but most answers refuse to provide a RegEx and instead say to use <code>startswith()</code> and <code>endswith()</code>. But since the page source could be massive, I'm worried about performance. I am new to Python, though, and perhaps I'm just not understanding how to use those methods.</p>