title: Windows CMD - Why Are Both Carets In Front of Exclamation Mark Removed When Delayed Expansion Is DISABLED?
body: <p>I am trying to understand more about how the Windows CMD parser works.  I have been reading several posts about the CMD parser, including this <a href="https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/4095133">one</a>, but I can't seem to figure out why both carets (^) in the following code are stripped when delayed expansion is DISABLED:</p>
  <pre><code>@echo off
  
  setlocal disabledelayedexpansion
  
  set $test_var=This is text with escaped delayed expansion syntax - ^^!$var1^^! and ^^!$var2^^!
  
  echo $test_var = %$test_var%
  
  echo.
  pause
  </code></pre>
  <p>I expected the result of running the code to produce the following output:</p>
  <pre><code>$test_var = This is text with escaped delayed expansion syntax - ^!$var1^! and ^!$var2^!
  </code></pre>
  <p>Instead, ALL carets are removed:</p>
  <pre><code>$test_var = This is text with escaped delayed expansion syntax - !$var1! and !$var2!
  </code></pre>
  <p>From reading the <a href="https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/4095133">post</a> about the parser, it is my understanding that Phase 2 removes special characters, which includes the caret (^) escape character.  From my reading it seems that only one (1) caret character should be removed.  Why are both carets removed?</p>
  <p>Thanks For Your Help!</p>