title: RegEx in java to replace a String
body: <p>I've been trying to replace this mathematical function <code>x^2*sqrt(x^3)</code> to this <code>pow(x,2)*Math.sqrt(pow(x,3))</code></p>
  
  <p>so this is the regex    </p>
  
  <pre><code>/([0-9a-zA-Z\.\(\)]*)^([0-9a-zA-Z\.\(\)]*)/ pow(\1,\2)
  </code></pre>
  
  <p>it works in ruby, but I can't find a way to do it in java, I tried this method </p>
  
  <pre><code>String function=  "x^2*sqrt(x^3)";
  
    Pattern p = Pattern.compile("([a-z0-9]*)^([a-z0-9]*)");
    Matcher m = p.matcher(function);
  
    String out = function;
  
    if(m.find())
    {
        System.out.println("GRUPO 0:" + m.group(0));
        System.out.println("GRUPO 1:" + m.group(1));
        out = m.replaceFirst("pow(" + m.group(0) + ", " + m.group(1) + ')');
    }
        String funcformat = out;
        funcformat = funcformat.replaceAll("sqrt\\(([^)]*)\\)", "Math.sqrt($1)"); 
  
        System.out.println("Return Value :"+ funcion );
        System.out.print("Return Value :"+ funcformat );
  </code></pre>
  
  <p>But still doesn´t work, the output is: <code>pow(x, )^2*Math.sqrt(x^3)</code> as I said before it should be <code>pow(x,2)*Math.sqrt(pow(x,3))</code>.
  Thank you!!</p>