title: How to get only the first instance of a substring from a string?
body: <p>I am using some code to check a text file for some information, <code>extractedInfo</code>, in between my search criteria <code>searchKey</code> and <code>searchEndKey</code>:</p>
  
  <pre><code>data1 = mytextfile
  searchKey = "https://cars/"
  searchEndKey = "/ford/" 
  extractedInfo = data1[data1.find(searchKey)+len(searchKey):data1.find(searchEndKey,data1.find(searchKey)+len(searchKey)+1)]
  </code></pre>
  
  <p>Which works as expected if there is only one instance of the search keys, but if there are multiple instances of it then it grabs all the info starting from the start of the first <code>searchKey</code> all the way to the end of the last <code>searchEndKey</code>.</p>
  
  <p>For example if the text file has in it:</p>
  
  <blockquote>
    <p>blah blah <a href="https://cars/123456/ford/" rel="nofollow noreferrer">https://cars/123456/ford/</a> blah blah</p>
  </blockquote>
  
  <p>My returned value is <code>123456</code>.</p>
  
  <p>But if the text file has in it:</p>
  
  <blockquote>
    <p>blah blah <a href="https://cars/123456/ford/" rel="nofollow noreferrer">https://cars/123456/ford/</a> blah blah blah blah
    <a href="https://cars/123456/ford/" rel="nofollow noreferrer">https://cars/123456/ford/</a> blah blah blah blah
    <a href="https://cars/123456/ford/" rel="nofollow noreferrer">https://cars/123456/ford/</a> blah blah</p>
  </blockquote>
  
  <p>My returned value is:
  <code>123456/ford/ blah blah blah blah https://cars/123456/ford/ blah blah blah blah https://cars/123456</code></p>
  
  <p>So is there a way I can tell python to stop after it has finished getting the info between the first search keys it has already found?</p>