title: How to match first characters with a powershell script
body: <p>I am trying to move files to a certain folder if they start with a letter and delete them if they start with anything other than a letter.</p>
  
  <p>My code:</p>
  
  <pre><code>Function moveOrDelete($source, $dest)
  {
      $aToZ = '^[a-zA-Z].*'
      $notALetter = '^[^a-zA-Z].*'
  
      Get-ChildItem -Path $source\$aToZ -Recurse | Move-Item -Destination $dest
  
      Get-ChildItem -Path $source\$notALetter -Recurse | Remove-Item
  }
  </code></pre>
  
  <p>As I understand it the caret will match on the first character when it's outside of the brackets. In other words, the regex in the <code>$aToZ</code> variable will match anything that begins with a letter. the <code>.*</code> part will allow the rest of the file name to be anything. The caret inside the brackets negates the statement so if the file name begins with anything other than a letter it will match. I can't get it to work and I'm not getting any errors which leads me to believe that my regex is wrong. </p>
  
  <p>I have checked this with online tools including this one: <a href="https://regex101.com/" rel="nofollow noreferrer">https://regex101.com/</a> and they check out. </p>
  
  <p>I have also used variations of the regex like <code>^[a-zA-Z]</code> that don't work. Some patterns like <code>[a-zA-Z]*</code> move the files but it's not the pattern that I want.</p>
  
  <p>Here is how I'm calling the funcion: </p>
  
  <pre><code>moveOrDelete ".\source" ".\dest"
  </code></pre>
  
  <p>And here are the sample file names I'm using:</p>
  
  <pre><code>a.txt
  z.txt
  1.txt
  .txt
  </code></pre>