title: How to trim results from a substring-with-regex match?
body: <p>I have this set of data in postgresql:</p>
  
  <pre><code>en_MY_V2_CID_MY_SEM_1_1_0_0
  en_MY_V2_CID_MY_SEM_2_101_1703_0
  en_MY_V2_CID_MY_SEM_2_101_1724_0
  en_MY_CID_MY_DIS_1_100_1705_0068
  en_MY_CID_MY_DIS_1_100_1705_0068
  </code></pre>
  
  <p>I want to extract the substring like these:</p>
  
  <pre><code>en_MY_V2_CID_MY_SEM_1
  en_MY_V2_CID_MY_SEM_2
  en_MY_V2_CID_MY_SEM_2
  en_MY_CID_MY_DIS_1
  en_MY_CID_MY_DIS_1
  </code></pre>
  
  <p>Problem is, the left-side structure is not constant so I can't grasp them using regex. Instead, the right-side structure <em>is</em> constant, with the format <code>_numbers_numbers_numbers_numbers</code>. So I try to do use this query in postgresql:</p>
  
  <pre><code>select substring(name from '_\d+_\d+_\d+$') from logs;
  </code></pre>
  
  <p>And get:</p>
  
  <pre><code>1_0_0
  101_1703_0
  101_1724_0
  100_1705_0068
  1705_0068
  </code></pre>
  
  <p>So the question is, how do I negate, or trim the previous substring so I will get my results?</p>