Why not just remove 0x
if the string starts with it? There's no need to use a regular expression for this - just a combination of startsWith
and substring
is simpler to understand (IMO):
String hexString = response.getResult();
if (hexString.startsWith("0x")) {
hexString = hexString.substring(2);
}
int value = Integer.parseInt(hexString, 16);