title: Using a regular expression to insert text in a match
body: <p>Regular Expressions are incredible. I'm in my regex infancy so help solving the following would be greatly appreciated.</p>
  
  <p>I have to search through a string to match for a P character that's not surrounded by operators, power or negative signs. I then have to insert a multiplication sign. Case examples are:</p>
  
  <pre><code>33+16*55P would become 33+16*55*P
  2P would become 2*P
  P( 33*sin(45) ) would become P*(33*sin(45))
  </code></pre>
  
  <p>I have written some regex that I think handles this although I don't know how using regex I can insert a character:</p>
  
  <p>The reg is I've written is:</p>
  
  <pre><code>[^\^\+\-\/\*]?P+[^\^\+\-\/\*]
  </code></pre>
  
  <p>The language where the RegEx will be used is ActionScript 3.</p>
  
  <p>A live example of the regex can be seen at:</p>
  
  <p><a href="http://www.regexr.com/39pkv" rel="nofollow">http://www.regexr.com/39pkv</a></p>
  
  <p>I would be massively grateful if someone could show me how I insert a multiplication sign in middle of the match ie P2, becomes P*2, 22.5P becomes 22.5P</p>
  
  <p>ActionScript 3 has search, match and replace functions that all utilise regular expressions. I'm unsure how I'd use string.replace( expression, replaceText ) in this context.</p>
  
  <p>Many thanks in advance</p>