title: Dynamic regex based string replacement in Java
body: <p>Inspired by this <a href="https://stackoverflow.com/a/17395203/1809463">regex-based answer</a> to <a href="https://stackoverflow.com/q/3835317/1809463">a unicode question</a> I now have following javascript code,
  which unescapes unicoded encoded character occurrences in strings.</p>
  
  <pre><code>var testString = "\\u53ef\\u4ee5NonUnicode\\u544a\\u8bc9\\u6211";
  print(testString)
  
  String.prototype.unescape = function() {
          return this.replace(/\\u([0-9a-f]{4})/g, 
                  function (whole, group1) {
                      return String.fromCharCode(parseInt(group1, 16));
                  }
              );
      };
  
  print(testString.unescape()) // outputs: 可以NonUnicode告诉我
  </code></pre>
  
  <p>I could not find a way in Java (1.7) to do this kind of dynamic regex replacement, there are only static approaches like <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)" rel="nofollow noreferrer">java.lang.String.replaceAll</a> or <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#group(int)" rel="nofollow noreferrer">java.util.regex.Matcher.group</a>, which returns the group, but has no means to set it.</p>
  
  <p>Is this even possible in Java? Are there any workarounds?</p>