title: PowerShell - Inserting newline char in string during regex replace
body: <p>I'm trying to search a string for some numbers and insert a new line before each, not including the first one.</p>
  
  <p>I don't seem to be able to use the traditional regex \n char to insert a newline. If I use the PowerShell escape character, the regex variable from the set is ignored.</p>
  
  <p>For a given source string of</p>
  
  <pre><code>$theString = "1. First line 2. Second line 3. Third line"
  </code></pre>
  
  <p>What I want is:</p>
  
  <pre>
  1. First Line
  2. Second Line
  3. Third line
  </pre>
  
  <p>So I tried this regex to find the numbers 2 to 9 followed by a period and a space:</p>
  
  <pre><code>$theString = $theString -replace '([2-9]\. )','\n$1'
  </code></pre>
  
  <p>but that yields:</p>
  
  <pre>
  1. First line\n2. Second line\n3. Third line
  </pre>
  
  <p>So I tried using the PowerShell escape character for a newline and put it inside double inverted commas:</p>
  
  <pre><code>$theString = $theString -replace '([2-9]\. )',"`n$1"
  </code></pre>
  
  <p>but that yields:</p>
  
  <pre>
  1. First Line
  Second Line
  Third line
  </pre>
  
  <p>I tried using <code>\r</code>, <code>\r\n</code>, <code>\`r</code>, <code>\`r\`n</code>, etc. trying to force the linebreak, but can't get it to happen without losing the ability to include the current regex variable.</p>