title: Regex expression to strip ending of word
body: <p>I have the following identifiers:</p>
  
  <pre><code>id1 = '883316040119_FRIENDS_HD'
  id2 = 'ZWEX01DE9463DB_DMD' 
  id3 = '35358fr1'
  id4 = 'as3d99j_br001'
  </code></pre>
  
  <p>I need a regex to get me the following output:</p>
  
  <pre><code>id1 = '883316040119'
  id2 = 'ZWEX01DE9463DB' 
  id3 = '35358'
  id4 = 'as3d99j'
  </code></pre>
  
  <p>Here is what I have so far -- </p>
  
  <pre><code>re.sub(r'_?([a-zA-Z]{2,4}?\d?(00\d)?)$','',vendor_id)
  </code></pre>
  
  <p>It doesn't work perfectly though, here is what it gives me:</p>
  
  <pre><code>BAD  - 883316040119_FRIENDS
  GOOD - ZWEX01DE9463DB
  GOOD - 35358
  GOOD - as3d99j
  </code></pre>
  
  <p>What would be the correct regular expression to get all of them? For the first one, I basically want to strip the ending if it is only underscores and letters, so <code>1928h9829_bundle_hd --&gt; 1928h9829</code>.</p>
  
  <p>Please note that I have hundreds of thousands of identifiers here, and it is required that I use a regular expression. I'm not looking for a python <code>split()</code> way to do it, as it wouldn't work.</p>