title: How to replace first and last part of each line with powershell
body: <p>I would like to use PowerShell to modify a text file.</p>
  
  <p>I would like to <strong>-replace</strong>:</p>
  
  <ul>
  <li><code>[REPLACE</code> at the beginning of each line with <code>ENJOY</code></li>
  <li><code>LINE]</code> at the end of each line with <code>LIFE</code></li>
  <li>only if the line starts with <code>[REPLACE</code> and ends with <code>LINE]</code></li>
  </ul>
  
  <p><strong>What would be the regex expression used in -replace to match this request ?</strong></p>
  
  <p><em>Example - File Input</em></p>
  
  <pre><code>[REPLACE_IN_THIS_LINE]
  [DO_NOT_REPLACE_IN_THIS_LINE_PLEASE]
  [REPLACE_VERY_MUCH_IN_THIS_LINE]
  Do not replace in this line[REPLACE_IN_THIS_LINE]
  </code></pre>
  
  <p><em>Example - File Output</em></p>
  
  <pre><code>ENJOY_IN_THIS_LIFE
  [DO_NOT_REPLACE_IN_THIS_LINE_PLEASE]
  ENJOY_VERY_MUCH_IN_THIS_LIFE
  Do not replace in this line[REPLACE_IN_THIS_LINE]
  </code></pre>
  
  <p>As you can see, in this example, only 2nd and 4th lines have changed...</p>
  
  <p>I came up with this for matching the string: <code>-match "^\[REPLACE.*LINE\]$"</code> but I don't know how to use <code>-replace</code> to correctly replace...</p>