title: Regex search multiple suffixes
body: <p>I have a big list of target words I am searching</p>
  
  <pre><code>words = ['Word1', 'Word2', 'Word3']
  </code></pre>
  
  <p>I've been told that a regular expression of this sort:</p>
  
  <pre><code>suffix = re.compile('(?:{words}) (\\w+)'.format(words='|'.join(words)))
  </code></pre>
  
  <p>Is pretty efficient, since it fails the regex evaluation immediately when a character that doesn't match the expression is met.</p>
  
  <p>However, the other way around is not efficient:</p>
  
  <pre><code>prefix = re.compile('(\\w+) (?:{words})'.format(words='|'.join(words)))
  </code></pre>
  
  <p>Is there an elegant way to instruct python's regex to do the search in reverse ?</p>
  
  <h2>Edit</h2>
  
  <p>I've been asked to add example usages:</p>
  
  <pre><code># prefix search
  title = re.compile('(?:Mr.|Mrs.|Ms.|Dr. |Lt.) (\\w+)')
  # suffix search
  company = re.compile('(\\w+) (?:Inc.| LLP.|ltd.|GMBH)')
  # invoking the regex
  all_people_names  = title.findall(document)
  all_company_names = company.findall(document)
  </code></pre>
  
  <h2>Edit 2</h2>
  
  <p>A lot of people had been skeptical regarding the significance of the timing differences.</p>
  
  <p>I've implemented the 2 methods: <code>endswith()</code> and <code>endswith_rev()</code> that reverses the string and the results as kabanus suggested.</p>
  
  <p>These are the results:</p>
  
  <p><a href="https://i.stack.imgur.com/zWtoz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zWtoz.png" alt="Timing"></a></p>
  
  <p>As you can see, it makes a <strong>huge</strong> difference, even with a small amount of suffixes.</p>