title: Java regex backreference for two digits
body: <p>I am working with a regex and I want to use it on the <code>replaceAll</code> method of the String class in Java.</p>
  
  <p>My regex works fine and <code>groupCount()</code> returns 11. So, when I try to replace my text using backreference pointing to the eleventh group, I am getting the first group with a "1" attached to it, instead of the group eleven.</p>
  
  <pre><code>String regex = "(&gt;[^&lt;]*?)((\+?\d{1,4}[ \t\f\-\.](\d[ \t\f\-\.])?)?(\(\d{1,4}([\s-]\d{1,4})?\)[\.\- \t\f])?((\d{2,6}[\.\- \t\f])+\d{2,6})|(\d{6,16})([;,\.]{1,3}\d{3,}#?)?)([^&lt;]*&lt;)";
  String text = "&lt;span style=\"font-size:11.0pt\"&gt;675-441-3144;;;78888464#&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;":
  String replacement = text.replaceAll(regex, $1&lt;a href="tel:$2"&gt;$2&lt;/a&gt;$11");
  </code></pre>
  
  <p>I am expecting to get the following result:</p>
  
  <pre><code>&lt;span style=\"font-size:11.0pt\"&gt;&lt;a href=\"tel:675-441-3144;;;78888464#\"&gt;675-441-3144;;;78888464#&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
  </code></pre>
  
  <p>But the $11 backreference is not returning the 11th group, it is returning the first group with a 1 attached to it, and instead I am getting the following result:</p>
  
  <pre><code>&lt;span style="font-size:11.0pt"&gt;&lt;a href="tel:675-441-3144"&gt;675-441-3144&lt;/a&gt;&gt;1o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
  </code></pre>
  
  <p>Can someone please tell me how to access the eleventh group of my pattern?</p>
  
  <p>Thanks.</p>