title: building a regex using a variable from another string in powershell
body: <p>I want to pass a string into a powershell function that can be used to form a regular expression for replace... however, i'm not sure how to form a regular expression using another powershell string.  Consider the following example:</p>
  <pre><code>function renamer {
      param(
          [String]$prefix,
          [String]$path
      )
  
      $path = $path -replace &quot;^$prefix&quot;, &quot;./mynewpath&quot;
      return $path
  }
  
  
  renamer -prefix &quot;C:/mycoolpath&quot; -path &quot;C:/mycoolpath/proj1&quot;
  
  # What I want renamer to return is this:
  #   /proj1
  
  </code></pre>