title: How to replace dates in text file with Powershell using regular expressions
body: <p>I've done much searching on this and haven't worked out the answer, but I feel like I am close!</p>
  
  <p>I have dates in a text file in the following format: <code>18/06/2012 23:00:43 (dd/mm/yyyy HH:MM:SS)</code> which I want to convert to: <code>2012-18-06 23:00:43 (yyyy-dd-mm HH:MM:SS)</code> using Powershell.</p>
  
  <p>To perform the conversion in a text editor using regular expressions I would do this: </p>
  
  <pre><code>Find: ([0-9]+)/+([0-9]+)/+([0-9]+)
  
  Replace with: \3-\2-\1
  </code></pre>
  
  <p>So I have tried using this same logic in a the following Powershell script:</p>
  
  <pre><code>(Get-Content C:\script\test.txt) | 
  Foreach-Object {$_ -replace "([0-9]+)/+([0-9]+)/+([0-9]+)", "(\3-\2-\1)"} | 
  Set-Content C:\script\test.txt
  </code></pre>
  
  <p>but that results in the following undesired change:</p>
  
  <blockquote>
    <p>\3-\2-\1 23:00:43</p>
  </blockquote>
  
  <p>Can anybody help me nail this?</p>
  
  <p>Many thanks in advance!</p>