title: Replace part of the string matching the pattern
body: <p>It's my first Python day, so please excuse me for this question</p>
  
  <p>The Problem:
  in a file replace every occurrence of 
  <strong>trim(column_name)</strong> with <strong>TRIM (TRIM (CHR (09) FROM column_name))</strong>. I've already sorted out how to do a pattern search and acquainted myself with the re.sub() function. </p>
  
  <p>the pattern that matches my case is</p>
  
  <pre><code>p = re.compile ('trim\([a-z0-9_]+\)',re.I)
  </code></pre>
  
  <p>but how do I replace the matching pattern preserving the column name???</p>
  
  <p>The needed output is, for example, as follows:</p>
  
  <pre><code>input: select trim(API12), trim(FIELD_CODE) from table
  output: select TRIM (TRIM (CHR (09) FROM API12)), TRIM (TRIM (CHR (09) FROM FIELD_CODE)) from table
  </code></pre>