No puedes usar el comodín $1 fuera de la función replace|replaceAll
Prueba con esto:
Código java:
Ver originalString text
= "/sudoif $exp(leviathan)>$exp(luis)"; String regex
= "\\$(?<command>\\w+)\\((?<player>\\w+)\\)"; Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String command
= matcher.
group("command"); String player
= matcher.
group("player"); System.
out.
printf("command: %s, player: %s\n", command, player
); }
Salida:
command: exp, player: leviathan
command: exp, player: luis