title: PowerShell regex script
body: <p>Have a list of usernames, they are formatted in one of two ways:</p>
  <p>John Smith</p>
  <p>John.Smith</p>
  <p>I would like to get just the last name from each line in a text file.</p>
  <p>I'm guessing I have to use a -replace or -remove command, just not sure how to format the regex.</p>
  <p>I have this:</p>
  <pre><code>$source = &quot;path\to\name\list.txt&quot;
  
  $final = &quot;path\to\final\output.txt&quot;
  
  (Get-Content $source -Raw) -replace &quot;^.\.|^.&quot;&quot;, &quot;&quot; | Set-Content $final
  </code></pre>
  <p>but it's not working.</p>