How to replace all non-supplementary chars, but leave all supplementary as is?

131 views Asked by At

I have a problem with Java Regex applied on supplementary chars

String x = new StringBuilder().appendCodePoint(0x10001).toString();
// x == "" (char['\uD800', '\uDC01']) - ok
String y = x.replaceAll("[\\x{10000}-\\x{10010}]", "*");
// y == "*" (char['*']) - ok
String z = x.replaceAll("[^\\x{10000}-\\x{10010}]", "*");
// z == "�*" (char['\uD800', '*']) - NOT ok

I'm expecting that x == z. What am I doing wrong? jdk1.8.0_144

0

There are 0 answers