fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Test
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. Pattern pattern = Pattern.compile("abfss?://(?:([^@/]*)@(\\d{1,3}(?:\\.\\d{1,3}){3}:\\d+)/([^/]+)|([^/]+)@([^.]+)(\\.[^/]+))(?:/(.+))?");
  9. String[] inputs = {
  10. "abfs://storage@myaccount.dfs.core.windows.net/selim/test.csv",
  11. "abfs://storage@127.0.0.1:10000/devstoreaccount1/selim/test.csv"
  12. };
  13. for (String s: inputs) {
  14. Matcher matcher = pattern.matcher(s);
  15. if (matcher.find()){
  16. if (matcher.group(5) != null) { // If original URL is found
  17. String fileSystem = matcher.group(4); //storage
  18. String accountName = matcher.group(5); //myaccount
  19. String accountSuffix = matcher.group(6); //.dfs.core.windows.net
  20. String relativePath = matcher.group(7); //selim/test.csv
  21. System.out.println(s + ":\nfileSystem: " + fileSystem + "\naccountName: " + accountName + "\naccountSuffix: '" + accountSuffix + "'\nrelativePath:" + relativePath + "\n-----");
  22. } else { // we have an Azurite URL
  23. String fileSystem = matcher.group(1); //storage
  24. String accountName = matcher.group(3); //devstoreaccount1
  25. String accountSuffix = ""; // empty (or do you need matcher.group(2) to get "127.0.0.1:10000"?)
  26. String relativePath = matcher.group(7); //selim/test.csv
  27. System.out.println(s + ":\nfileSystem: " + fileSystem + "\naccountName: " + accountName + "\naccountSuffix: '" + accountSuffix + "'\nrelativePath:" + relativePath + "\n-----");
  28. }
  29. }
  30. }
  31. }
  32. }
Success #stdin #stdout 0.18s 56036KB
stdin
Standard input is empty
stdout
abfs://storage@myaccount.dfs.core.windows.net/selim/test.csv:
fileSystem: storage
accountName: myaccount
accountSuffix: '.dfs.core.windows.net'
relativePath:selim/test.csv
-----
abfs://storage@127.0.0.1:10000/devstoreaccount1/selim/test.csv:
fileSystem: storage
accountName: devstoreaccount1
accountSuffix: ''
relativePath:selim/test.csv
-----