fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.lang.*;
  4. import java.io.*;
  5. import java.nio.*;
  6. import java.util.function.*;
  7. import java.util.regex.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class requal
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // Initializing test data.
  15. // Will compare Strings in batch1, batch2 at the same array position.
  16. //
  17. String[] batch1 = {
  18. "/mypath/check/10.10/-123.11"
  19. , "/mypath/check/10.10/-123.11"
  20. , "/mypath/check/10.10/-123.11"
  21. , "/mypath/check/10.10/123.11"
  22.  
  23. , "/mypath/check/10.10/-123.11"
  24. , "/mypath/check/10.11/-123.11"
  25. };
  26. String[] batch2 = {
  27. "/mypath/check/10.101/-123.112"
  28. , "/mypath/check/10.101/-123.11"
  29. , "/mypath/check/10.10/-123.112"
  30. , "/mypath/check/10.101/123.112"
  31.  
  32. , "/mypath/check/10.121/-123.152"
  33. , "/mypath/check/10.12/-123.11"
  34. };
  35.  
  36. // Regex pattern used for normalization:
  37. // - Basic pattern: decimal point followed by 2 or 3 digits
  38. // - Optional part: 3rd digit of the basic pattern
  39. // - Additional context: Pattern must match at the end of the string or be followed by a non-digit character.
  40. //
  41. Pattern re_p = Pattern.compile("([.][0-9]{2})[0-9]?(?:$|(?![0-9]))");
  42.  
  43. // Replacer routine for processing the regex match. Returns capture group #1
  44. Function<MatchResult, String> fnReplacer= (MatchResult m)-> { return m.group(1); };
  45.  
  46.  
  47. // Processing each test case
  48. // Expected result
  49. // match
  50. // match
  51. // match
  52. // match
  53. // mismatch
  54. // mismatch
  55. //
  56. for ( int i = 0; i < batch1.length; i++ ) {
  57. String norm1 = re_p.matcher(batch1[i]).replaceAll(fnReplacer);
  58. String norm2 = re_p.matcher(batch2[i]).replaceAll(fnReplacer);
  59.  
  60. if (norm1.equals(norm2)) {
  61. System.out.println("Url pair #" + Integer.toString(i) + ": match ( '" + norm1 + "' == '" + norm2 + "' )");
  62. } else {
  63. System.out.println("Url pair #" + Integer.toString(i) + ": mismatch ( '" + norm1 + "' != '" + norm2 + "' )");
  64. }
  65. }
  66. }
  67. }
Success #stdin #stdout 0.15s 37824KB
stdin
Standard input is empty
stdout
Url pair #0: match ( '/mypath/check/10.10/-123.11' == '/mypath/check/10.10/-123.11' )
Url pair #1: match ( '/mypath/check/10.10/-123.11' == '/mypath/check/10.10/-123.11' )
Url pair #2: match ( '/mypath/check/10.10/-123.11' == '/mypath/check/10.10/-123.11' )
Url pair #3: match ( '/mypath/check/10.10/123.11' == '/mypath/check/10.10/123.11' )
Url pair #4: mismatch ( '/mypath/check/10.10/-123.11' != '/mypath/check/10.12/-123.15' )
Url pair #5: mismatch ( '/mypath/check/10.11/-123.11' != '/mypath/check/10.12/-123.11' )