title: Java Regex recursive match
body: <p>I have a string like this:</p>
  
  <pre><code>IF(expr1,text1,IF(expr2,text2,IF(expr3,text3,text4)))
  </code></pre>
  
  <p>I need to process <code>IF(expr3,text3,text4)))</code> so the above become </p>
  
  <pre><code> IF(expr1,text1,IF(expr2,text2,new_text))
  </code></pre>
  
  <p>I need to keep doing this until I have</p>
  
  <pre><code> IF(expr1,text1,new_text3)
  </code></pre>
  
  <p>My pattern string <code>"IF\\(.*?,.*?,.*?\\)"</code> will match the whole thing. Not the <code>IF(expr3,text3,text4)))</code>.</p>
  
  <p>Java code:</p>
  
  <pre><code>String val = "IF(expr1,text1,IF(expr2,text2,IF(expr3,text3,text4)))";
  String regx = "IF\\(.*?,.*?,.*?\\)";  
  Pattern patt1 = Pattern.compile(regx);
  Matcher m2 = patt1.matcher(val);
  while (m2.find()) { 
      String val0 = m2.group();
      System.out.println( val0 ); 
  }  
  </code></pre>