title: Regex brings all lines. I want to make PS script to find all password pattern in File server
body: <p>I am trying to make powershell scripts for search all documents and txt files to find Password pattern. Actually my code is working fine. My regex is capture password but it brings all lines.</p>
  <p><em><strong>Regex Pattern</strong></em></p>
  <p>&quot;&quot;&quot; .<em>(?=.{8,20})(?=.</em>[a-z])(?=.<em>[A-Z])(?=.</em>[0-9])(?=.<em>[!^#+$%&amp;{()=}?</em>-|¨@.,:;,]).* &quot;&quot;&quot;</p>
  <p><a href="https://i.stack.imgur.com/wm5UN.png" rel="nofollow noreferrer">Samples</a>
  <a href="https://i.stack.imgur.com/LUn5V.png" rel="nofollow noreferrer">Samples2</a></p>
  <p>My regex bring all Line. How can fix this error.</p>
  <p><em><strong>PS Code</strong></em></p>
  <pre><code>$Path = &quot;c:\users\XXXXXXX&quot;
  $output_file = ‘C:\Users\XXXXXXXX\Desktop\Result.txt’
  $ALLWORDS =Get-ChildItem $Path  -Recurse -ErrorAction SilentlyContinue
  
  foreach ($WORDS in $ALLWORDS) { #
  $Word = New-Object -ComObject Word.Application
  $Word.Visible = $false
  $regex = ‘\b.*(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!^#+$%&amp;{()=}?*\-|¨@.,:;,]).*\b’
  $Doc = $Word.Documents.Open($WORDS.FullName, $false, $true)
  $paras = $doc.Paragraphs
  echo $paras.count
               
                      foreach($para in $paras){
                    if( $para.range.text -match $regex)  { 
                    $1=$matches.Values,$Words.Name | Out-File $output_file -Append
                    Write-Host $matches.Values, $words.Name 
                      }
                      }
                       
      $Doc.Close()
      $Word.Quit()
      $Word = $null
      }
  </code></pre>