fork download
  1. class LatLong {
  2. static String MINUTE = "[0-5]?\\d";
  3. static String MINUTE_STRICT = "[1-5]?\\d";
  4. static String MINUTE_FILL = "[0-5]\\d";
  5.  
  6. static String SECOND = "[0-5]?\\d(\\.\\d+)?";
  7. static String SECOND_STRICT = "[1-5]?\\d(\\.\\d+)?";
  8. static String SECOND_FILL = "[0-5]\\d(\\.\\d+)?";
  9.  
  10. static String DEGREE_LAT = "[+-]?(?:[0-8]?\\d|90)";
  11. static String DEGREE_LAT_STRICT = "[+-]?(?:[1-8]?\\d|90)";
  12.  
  13. static String DEGREE_LONG = "[+-]?(?:180|1[0-7]\\d|0?\\d?\\d)";
  14. static String DEGREE_LONG_STRICT = "[+-]?(?:180|1[0-7]\\d|[1-9]?\\d)";
  15.  
  16. static String PAIR_1 =
  17. DEGREE_LAT + "[*dD]" + "\\s*" +
  18. MINUTE + "[']" + "\\s*" +
  19. SECOND + "[\"]" + "\\s*" + "[NS]" +
  20. "\\s*" +
  21. DEGREE_LONG + "[*dD]" + "\\s*" +
  22. MINUTE + "[']" + "\\s*" +
  23. SECOND + "[\"]" + "\\s*" + "[EW]";
  24.  
  25. static String PAIR_2 =
  26. DEGREE_LAT + "[*dD]" + "\\s*" +
  27. MINUTE + "[']" + "\\s*" +
  28. SECOND + "[\"]" +
  29. "\\s*" +
  30. DEGREE_LONG + "[*dD]" + "\\s*" +
  31. MINUTE + "[']" + "\\s*" +
  32. SECOND + "[\"]";
  33.  
  34. static String PAIR_3 =
  35. DEGREE_LAT + ":" +
  36. MINUTE_FILL + ":" +
  37. SECOND_FILL + "\\s*" + "[NS]" +
  38. "\\s*" +
  39. DEGREE_LONG + ":" +
  40. MINUTE_FILL + ":" +
  41. SECOND_FILL + "\\s*" + "[EW]";
  42.  
  43. public static void main(String args[]) {
  44.  
  45. System.out.println("90:00:00.0N 180:00:00.0E".matches(PAIR_3));
  46.  
  47. System.out.println("45* 12' 22\"N 46* 12' 22\"E".matches(PAIR_1));
  48.  
  49. System.out.println("23* 34' 42\" 124* 34' 42\"".matches(PAIR_2));
  50. }
  51. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
true
true
true