title: Python, how to compare substrings?
body: <p>I'm trying to compare substrings, and if I find a match, I break out of my loop. Here's an example of a few strings: </p>
  
  <pre><code>'something_tag_05172015.3', 'B_099.z_02112013.1', 'something_tag_05172015.1' ,'BHO98.c_TEXT_TEXT_05172014.88'. 
  </code></pre>
  
  <p>The comparison should only compare the string I'm looking for, and everything in the same strings to what is to the left of the last underscore '_' in the strings. So, <code>'something_tag'</code> should match only <code>'something_tag_05172015.3'</code> and <code>'something_tag_05172015.1'</code>.</p>
  
  <p>What I did to do this was I split on the underscores and did a join on all elements but the last element in the split to compare against my test string (this drops everything to the right of the last underscore. Though it works, there's gotta be a better way. I was thinking maybe regex to remove the last underscore and digits, but it didn't work properly on a few tags. </p>
  
  <p>Here's an example of the regex I was trying: <code>re.sub('_\d+\.\d+', '', string_to_test)</code></p>