title: regex: remove all but groups
body: <p>I need to remove all but matched groups in regex. A toy example would be:</p>
  
  <pre><code>echo 'spam 123 ham 345 eggs' | perl -pe 's/( \d+ )/SOMETHING/g'
  
  123 345
  </code></pre>
  
  <p>What perl regex will remove everything but the matched groups? The matched group can be more complex than just digits - I can define the groups to match, but outside of the groups I can contain any random characters</p>