title: Trying to match this using regular expressions in PowerShell
body: <p>I am trying to use regular expressions to match certain lines in a file, but I am having some trouble.</p>
  
  <p>The file contains text like this:</p>
  
  <pre><code>Mario, 123456789
  Luigi, 234-567-890
  Nancy, 345 5666 77533
  Bowser, 348759823745908732589
  Peach, 534785
  Daisy, 123-456-7890
  </code></pre>
  
  <p>I'm trying to match just the numbers as either XXX-XXX-XXX or XXX XXX XXX pattern.</p>
  
  <p>I've tried a few different ways, but it always expects something I don't want it to or it tell me everything is false.</p>
  
  <p>I'm using PowerShell to do this.</p>
  
  <p>At first I tried:</p>
  
  <pre><code>{$match = $i -match "\d{3}\-\d{3}\-\d{3}|\d{3}\ \d{3}\ \d{3}"
  Write-Host $match}
  </code></pre>
  
  <p>But when I do that it matches the long strong of numbers and <code>XXX-XXX-XXXXX</code>.</p>
  
  <p>I read something saying that n would match the exact quantity, so I tried that...</p>
  
  <pre><code>{$match = $i -match "\d{n3}\-\d{n3}\-\d{n3}|\d{n3}\ \d{n3}\ \{n3}"
  Write-Host $match}
  </code></pre>
  
  <p>That made everything false...</p>
  
  <p>So I tried</p>
  
  <pre><code>{$match = $i -match "\d\n{3}\-\d\n{3}\-\d\n{3}|\d\n{3}\ \d\n{3}\ \d\n{3}"
  </code></pre>
  
  <p>I also tried the lazy quantifier, <code>?</code>:</p>
  
  <pre><code>{$match = $i -match "\d{3?}\-\d{3?}\-\d{3?}|\d{3?}\ \{3?}\ \{3?}"
  Write-Host $match}
  </code></pre>
  
  <p>Still false...</p>
  
  <p>The final thing I tried was this...</p>
  
  <pre><code>{$match = $i -match "\d[0-9\{3\}\-\d[0-9]\{3\}\-\d[0-9]{3\}|\d[0-9]\{3\}\ \d[0-9]\{3}\ \d[0-9]\{3\}"&lt;br&gt;
  Write-Host $match}
  </code></pre>
  
  <p>Still no luck...</p>