我的正则表达式有两个来自相同代码的不同输出......但我不知道什么是错的.这是一段代码,希望你能帮助我.谢谢!
String s = "48° 18? 13,94? nördliche Breite, "
+ "11° 34? 31,98? östliche Länge";
String kommazahl = "[0-9]{1,2}([\\.,][0-9]+)?";
String zahl = "[0-9]{1,2}";
Pattern p1 = Pattern.compile("("+ zahl +"[°/| ]{1,2}"+ zahl +"(['?/| ]{1,2}("+ kommazahl +")?)?).*"
+"("+ zahl +"[°/| ]{1,2}"+ zahl +"(['?/| ]{1,2}("+ kommazahl +")?)?).*");
Matcher m1 = p1.matcher(s);
System.out.println(m1.group(1) + "\n" + m1.group(5));
// Output should be:
// 48° 18? 13,94
// 11° 34? 31,98
// Output is:
// 48° 18? 13,94
// 1° 34? 31,98
Run Code Online (Sandbox Code Playgroud)