title: Regex replace the substitution string
body: <p>Let's consider the following example:</p>
  
  <pre><code>String s = str.replaceAll("regexp", "$1");
  </code></pre>
  
  <p>Some languages allow us to specify <code>\U$1</code> in place of <code>$1</code> which converts matched groups with uppercase letters. How can I achieve the same using Java?</p>
  
  <p>I know we can use <code>Pattern</code> class and get the group and convert it to uppercase, but that's not what I am looking for. I want to just change <code>$1</code> with something that gets the job done.</p>
  
  <p>I have also tried:</p>
  
  <pre><code>String s = str.replaceAll("regexp", "$1".toUpperCase());
  </code></pre>
  
  <p>But it looks like <code>"$1".toUpperCase()</code> is <code>"$1"</code> and not the match. I confirmed it using:</p>
  
  <pre><code>String s = str.replaceAll("regexp", method("$1"));
  
  // method declared as method()
  private static String method(String s) {
      System.out.println(s); // prints "$1"
      return s;
  }
  </code></pre>
  
  <p>Is it even allowed in Java?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>String s = "abc";
  System.out.println(s.replaceAll("(a)", "$1")); // should print "Abc"
  </code></pre>
  
  <p><strong><em>EDIT FOR POSSIBLE DUPE:</em></strong></p>
  
  <p>I am not looking for way using <code>m.group()</code>, is it possible using something like <code>\U$1</code> in place of <code>$1</code> with <code>replaceAll()</code></p>