title: In python, how do I search for only one word before my selected substring
body: <p>Given long list of lines in a text file I only want to return the substring that immediately precedes, for example, the word dog (the word that describes dog).  So for example say there are these lines containing dog:</p>
  
  <pre><code>“hotdog” “big dog” “is dogged” “dog spy” “with my dog” “brown dogs”
  </code></pre>
  
  <p>In this case the desired result is only “big” “my” “brown” </p>
  
  <p>I have used this python script </p>
  
  <pre><code>import re
  with open('titles_500subset.txt') as searchfile:
      for line in searchfile:
          line = line.lower()
          d = re.search('(.+?) eye', line)
          if d:
              found = d.group(1)
              print found
  </code></pre>
  
  <p>This would return <code>“with my”</code> and <code>“big”</code> </p>
  
  <p>So here I wouldn't get <code>“brown”</code> and I get all the terms <code>“with my”</code></p>
  
  <p>How do I specify just one word before dog (obviously I cannot put a space before <code>(.+?)</code> as then I would exclude <code>“big”</code> and <code>“brown”</code> as they are at the start of a line)?</p>
  
  <p>How can I specify just one character to come after dog e.g. <code>“s”</code> to get only words before dogs and dog but not dogged?</p>
  
  <p>And in a perfect case I’d also like to be able to specify results to exclude, e.g. <code>“my”</code>.</p>
  
  <p>Many thanks</p>