title: how do I rename files in Powershell with regex?
body: <p>I have some files with word characters and numbers at the end of filename. For some reason my regex is not working. Here are examples of my filenames:</p>
  
  <pre><code>test abc12345.zip
  abcd def98765.zip
  test xyz23456.zip
  </code></pre>
  
  <p>Here is my regex:</p>
  
  <pre><code>dir | rename-item -NewName {$_.name -replace "(\w\w\w\d\d\d\d\d.zip)","[$1].zip"}
  </code></pre>
  
  <p>When I run the selection snippet it removes:</p>
  
  <pre><code>abc12345
  def98765
  xyz23456
  </code></pre>
  
  <p>from the files names and just inserts the brackets:</p>
  
  <pre><code>test [].zip
  abcd [].zip
  test [].zip
  </code></pre>
  
  <p>How do I keep the contents within the brackets? Not sure why my code is removing everything in between the []</p>
  
  <pre><code>test [abc12345].zip
  abcd [def98765].zip
  test [xyz23456].zip
  </code></pre>