title: Powershell find non-ASCII characters in text file
body: <p>I am trying to find a way using Powershell Script to do the following.</p>
  
  <ol>
  <li>For each line in text file, check if line contains non-ASCII characters</li>
  <li>If line contains non-ASCII characters, output to separate file</li>
  <li>If line does not contain non-ASCII characters, skip to next line</li>
  </ol>
  
  <p>By non-ASCII characters, I'm referring to non keyboard characters, e.g. accented characters, characters from another language, etc.</p>
  
  <p><strong>Sample Data</strong></p>
  
  <pre><code> - 张伟
   - குழந்தைகளுக்கான பெயர்கள்
   - 日本人の氏名
   - Full Name
   - Léna Rémi
  </code></pre>
  
  <p><strong>Output Data</strong></p>
  
  <pre><code> - 张伟
   - குழந்தைகளுக்கான பெயர்கள்
   - 日本人の氏名
   - Léna Rémi
  </code></pre>
  
  <p>I found the regex in other threads to remove non-ASCII characters but I couldn't seem to make it work.</p>
  
  <p>Please help!</p>
  
  <p>** EDIT **
  Thanks everyone for the help! I have managed to do what I wanted with the below script.</p>
  
  <pre><code>$nonASCII = "[^\x00-\x7F]"
  foreach ($_ in [System.IO.File]::ReadLines($source)){
      if ($_ -cmatch $nonASCII){
          write-output $_ | out-File $output -append        
      }
  }
  </code></pre>