Ver Mensaje Individual
  #6 (permalink)  
Antiguo 28/03/2013, 14:32
LuisChavezB
 
Fecha de Ingreso: diciembre-2011
Mensajes: 152
Antigüedad: 12 años, 4 meses
Puntos: 34
Respuesta: Duda con expresiones regulares

No puedes usar el comodín $1 fuera de la función replace|replaceAll

Prueba con esto:
Código java:
Ver original
  1. String text = "/sudoif $exp(leviathan)>$exp(luis)";
  2. String regex = "\\$(?<command>\\w+)\\((?<player>\\w+)\\)";
  3. Pattern pattern = Pattern.compile(regex);
  4. Matcher matcher = pattern.matcher(text);
  5. while (matcher.find()) {            
  6.     String command = matcher.group("command");
  7.     String player = matcher.group("player");
  8.     System.out.printf("command: %s, player: %s\n", command, player);
  9. }

Salida:

command: exp, player: leviathan
command: exp, player: luis