title: Could regex be used in this PowerShell script?
body: <p>I have the following code, used to remove spaces and other characters from a string $m, and replace them with periods ('.'):</p>
  <pre><code>Function CleanupMessage([string]$m) {
    $m = $m.Replace(' ', &quot;.&quot;)           # spaces to dot
    $m = $m.Replace(&quot;,&quot;, &quot;.&quot;)           # commas to dot
    $m = $m.Replace([char]10, &quot;.&quot;)      # linefeeds to dot
  
    while ($m.Contains(&quot;..&quot;)) {
      $m = $m.Replace(&quot;..&quot;,&quot;.&quot;)         # multiple dots to dot
    }
  
    return $m
  }
  </code></pre>
  <p>It works OK, but it seems like a lot of code and can be simplified.  I've read that regex can work with patterns, but am not clear if that would work in this case.  Any hints?</p>