Tengo una gran expresión regular que coincide con excel como coordenadas en un texto, que debería ignorar los rangos. Noté un cambio en el comportamiento al actualizar la versión de Java. Simplifiqué la expresión regular y el código.
Aquí está el código:
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String regex = "((?<![\\w$:])\\$?[AZ]{1,3}\\$?[1-9][0-9]{0,3}(?![\\w(:]))"; String input = "=A1:B2"; Pattern withCE = Pattern.compile(regex,Pattern.CANON_EQ); Matcher cellReferenceswithCE = withCE.matcher(input); Pattern withoutCE = Pattern.compile(regex); Matcher cellReferenceswithoutCE = withoutCE.matcher(input); System.out.println("Java version : " + System.getProperty("java.version")); System.out.println("regex : " + regex); System.out.println("String input : " + input); System.out.println("w/ canon eq : " + cellReferenceswithCE.find() + "" + (cellReferenceswithCE.reset().find()?" => "+cellReferenceswithCE.group():"")); System.out.println("w/o canon eq : " + cellReferenceswithoutCE.find() + "" + (cellReferenceswithoutCE.reset().find()?" => "+cellReferenceswithoutCE.group():"")); } }Y aquí está el resultado con diferentes versiones de Java:
Java version : 1.8.0_302 regex : ((?<![\w$:])\$?[AZ]{1,3}\$?[1-9][0-9]{0,3}(?![\w(:])) String input : =A1:B2 w/ canon eq : false w/o canon eq : false Java version : 9.0.1 regex : ((?<![\w$:])\$?[AZ]{1,3}\$?[1-9][0-9]{0,3}(?![\w(:])) String input : =A1:B2 w/ canon eq : true => B2 w/o canon eq : false Cualquier cosa anterior a 1.8.0_302 tiene el mismo comportamiento que 1.8.0_302
Cualquier cosa posterior a 9.0.1 tiene el mismo comportamiento que 9.0.1
¿Cuál es la forma correcta de recuperar el comportamiento que tenía en Java 8? ¿Debo actualizar la expresión regular o debo eliminar la equivalencia canónica?
¿Qué versión tiene el comportamiento esperado?