title: How to extract first and last name from a string
body: <p>I'm trying to figure out the regex with powershell, and can't seem to get what I want.</p>
  
  <p>Given the string...</p>
  
  <pre><code>John Doe - Specialist - Data - Person
  </code></pre>
  
  <p>I want to extract the first and list name from this string and add it to an array. I am trying the following...</p>
  
  <pre><code>$firstName = @()
  $lastName = @()
  $string = 'John Doe - Specialist - Data - Person'
  
  $firstName += $string -replace '\s+*','' #does not work
  $lastName += $string -replace '\*\s+\*','\*' #does not work
  </code></pre>
  
  <h1>Update</h1>
  
  <p>So far, this works...</p>
  
  <pre><code>$firstName, $lastName = $string -split "\s"
  $lastName, $junk = $lastName -split "\s"
  $firstNames += $firstName
  $lastNames += $lastName
  </code></pre>
  
  <p>But it's messy, and I want to know if there is a better way to handle this.</p>