title: Replace all substrings in Javascript with infuenced string
body: <p>I am expecting an input to look like: "x^3" and would like to replace this with a string of "pow(x, 3)". However the whole input may look like "x^3 + x^2 + 4". Here I want each instance of the "^" operator to signify a conversion to the "pow()" substring instead. </p>
  
  <p>This means that the substring I am replacing it with is influenced by what it finds, but I need wildcard operators either side of the "^" if I am to do it with regular expressions. </p>
  
  <p>Is there a way to "store" what the wildcard happens to be at a given instance to reinsert it in the replacement string? </p>
  
  <p>i.e. in x^3, the 3 gets stored and put back into pow(x, 3)</p>
  
  <p>Cases:</p>
  
  <p>"x^2" -> "pow(x, 2)"</p>
  
  <p>"x^3 + x^2" -> "pow(x,3) + pow(x, 2)"</p>
  
  <p>"x^4 + y^19" -> "pow(x, 4) + pow(y, 19)"</p>