title: Store delimiter and delimiter positions before replacing them in python
body: <p>I'm working on a text pattern problem. I've the following input - </p>
  
  <pre><code>term = 'CG-14/0,2-L-0_2'
  </code></pre>
  
  <p>I need to remove all the possible punctuation (delimiters) from the input term. Basically I need the following output from the input term - </p>
  
  <pre><code>'CG1402L02'
  </code></pre>
  
  <p>I also need to store (in any format (object, dict, tuple etc.)) the delimiter and the position of the delimiter before removing the delimiters. </p>
  
  <p>Example of the output (If returned as tuple) - </p>
  
  <pre><code>((-,2), (/,5), (,,7), (-,9), (-,11), (_,13))
  </code></pre>
  
  <p>I'm able to get the output using the following python code - </p>
  
  <pre><code>re.sub(r'[^\w]', '', term.replace('_', ''))
  </code></pre>
  
  <p>But how do I store the delimiter and delimiter position (in the most efficient way) before removing the delimiters?</p>