title: Regex does not match when run in a script, but matches when run in console?
body: <p>I have the following code, that looks if some values match a regex</p>
  <pre><code>$ValueRegex = [PSCustomObject]@{
      &quot;year&quot; = &quot;^(201[0-9]|2020)$&quot;
      &quot;color&quot; = &quot;^#(?:[0-9a-fA-F]{6})$&quot;
      &quot;ID&quot; = &quot;^\d{9}$&quot;
  }
  &lt;#
      $SplitUp looks like this, each row is an object:
      year:2019
      ID:599245247
      color:#ffffff
  #&gt;
  foreach ($b in $SplitUp) {
      $x = $b -split &quot;:&quot;
      $CompareVal = $ValueRegex | Select-Object -ExpandProperty $x[0]
      if ($CompareVal) {
          $Compare = $x[1]
          if ($Compare -match $CompareVal) { 
              $MatchCount++
          } else { 
              #Print Debug Info
              &quot;'{0}' -match '{1}'&quot; -f $Compare, $CompareVal
              $x
              pause
          }
      }
  }
  </code></pre>
  <p>The weird thing that happens is, that sometimes it doesn't match even though it should.
  As you can see I print a debug info when something does not match, where I output what exactly got compared to each other etc. one output looks like this:</p>
  <pre><code>'2019' -match '^(201[0-9]|2020)$'
  year
  2019
  </code></pre>
  <p>the thing is - it should match. If I run this <code>'2019' -match '^(201[0-9]|2020)$'</code> in a new PowerShell Console window, it says it is <code>True</code>. In my Skript it says it's <code>False</code>.</p>
  <p>What is happening? I tried that in Visual Studio Code and in PowerShell ISE, both the same result</p>