Regex replace the substitution string
\\U
is not implemented in the java regex AFAIK and you can't do it with a regex as such (.NET
has it IIRC). It's a bit verbose, but one way to do it would be:
String test = "abc";
Pattern p = Pattern.compile("(a)");
Matcher m = p.matcher(test);
StringBuilder sb = new StringBuilder();
if (m.find()) {
String match = test.substring(m.start(1), m.end(1));
m.appendReplacement(sb, match.toUpperCase());
}
m.appendTail(sb);
System.out.println(sb.toString());