title: Ruby regex replace some subpattern captures
body: <p>I have regex for path parsing. Below is the part of regex that repeats multiple times.</p>
  
  <pre><code>dir_pattern = /
      \/?
      (?&lt;dir&gt;  #pattern to catch directory
          [^[:cntrl:]\/\n\r]+  #directory name
      )
      (?=\/)  #indistinguishable from file otherwise
  /x  
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>/really/long/absolute/path/to/file.extension
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>to/really/long/file.extension
  </code></pre>
  
  <p>I want to cut off some (not all directories) and reorder remaining ones. How could I achieve that?</p>
  
  <p>Since I'm already using regexes for filtering files needed, I would like to keep using them.</p>