title: Regex Postgresql: Remove the last part of string recursively
body: <p>I have a string that needs to be trimmed through removing words from the end of the string. For instance, if the words <code>ltee.</code>, <code>company</code>, <code>co.</code>, or any number appear then they should be removed and it should keep removing if the "new" end of the string is still in the list.</p>
  
  <p>Suppose the string <code>PUBLIC SCHOOL 2012 LTEE.</code>. First, the word <code>LTEE</code> should be removed to get <code>PUBLIC SCHOOL 2012</code> and then the number <code>2012</code> should be removed because it is a number at the end.</p>
  
  <p>I attempted to get this behaviour through the following:</p>
  
  <pre><code> select upper(regexp_replace(lower('PUBLIC SCHOOL 2012 LTEE.'),
                              '\d*$|\s(ltee|ltee.|company|co|co.|liability)$',
                              '','g'))
  </code></pre>
  
  <p>However, I am just getting <code>PUBLIC SCHOOL 2012</code> with the number at the end.</p>
  
  <p>Is there a way to remove the number as well? How about if there is another word besides LTEE.?</p>
  
  <p>For instance, the string <code>PUBLIC SCHOOL 2012 LTEE. CO</code> should become <code>PUBLIC SCHOOL</code> removing <code>CO</code>, then <code>LTEE.</code> and finally <code>2012</code>.</p>
  
  <p>Thanks</p>