fork(2) download
  1. import java.nio.file.Path;
  2. import java.nio.file.Paths;
  3. import java.util.regex.Pattern;
  4.  
  5. class Ideone
  6. {
  7. public Pattern LEADING_SLASHES = Pattern.compile("^(/|\\\\)+");
  8. public String removeLeadingSlashes(String path) {
  9. return LEADING_SLASHES.matcher(path).replaceFirst("");
  10. }
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15.  
  16. Path ESPath = Paths.get("\\es-module-repo\\fdea3319-18ea-4bd5-8ae2-2662d6f2ba72\\foo.mjs");
  17.  
  18. System.out.print("\\es-module-repo\\fdea3319... is ");
  19. if (ESPath.isAbsolute()) {
  20. System.out.print("an absolute ");
  21. } else {
  22. System.out.print("not absolute ");
  23. }
  24. System.out.println("path.");
  25.  
  26. Path ESPath2 = Paths.get("/es-module-repo/fdea3319-18ea-4bd5-8ae2-2662d6f2ba72/foo.mjs");
  27. System.out.print("/es-module-repo/fdea3319... is ");
  28.  
  29. if (ESPath2.isAbsolute()) {
  30. System.out.print("an absolute ");
  31. } else {
  32. System.out.print("not absolute ");
  33. }
  34. System.out.println("path.");
  35.  
  36. System.out.print("ESPath:" + ESPath.toString());
  37. if (ESPath.toString().startsWith("\\")) {
  38. System.out.println(" ESPath is Absolute!");
  39. }
  40. System.out.println(" ");
  41.  
  42. System.out.print("ESPath2:" + ESPath2.toString());
  43. if (ESPath2.toString().matches("(\\|\\\\/).*")) {
  44. System.out.println("ESPath2 is Absolute!");
  45. }
  46. System.out.println(" ");
  47.  
  48. Path ESPath3 = Path.of(new Ideone().removeLeadingSlashes(ESPath.toString()));
  49. System.out.println("Modified ESPath: " + ESPath3);
  50.  
  51. String Str3 = ESPath.toString().replaceAll("\\\\", "/");
  52. System.out.println("Regex: " + Str3);
  53. }
  54. }
Success #stdin #stdout 0.14s 46308KB
stdin
Standard input is empty
stdout
\es-module-repo\fdea3319... is not absolute path.
/es-module-repo/fdea3319... is an absolute path.
ESPath:\es-module-repo\fdea3319-18ea-4bd5-8ae2-2662d6f2ba72\foo.mjs ESPath is Absolute!
 
ESPath2:/es-module-repo/fdea3319-18ea-4bd5-8ae2-2662d6f2ba72/foo.mjs 
Modified ESPath: es-module-repo\fdea3319-18ea-4bd5-8ae2-2662d6f2ba72\foo.mjs
Regex: /es-module-repo/fdea3319-18ea-4bd5-8ae2-2662d6f2ba72/foo.mjs