fork 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_azurite = Pattern.compile("abfss?://([^@/]*)@(\\d{1,3}(?:\\.\\d{1,3}){3}:\\d+)/([^/]+)(?:/(.+))?");
  9. Pattern pattern_original = Pattern.compile("abfss?://([^/]+)@([^.]+)(\\.[^/]+)(?:/(.+))?");
  10. String[] inputs = {
  11. "abfs://storage@myaccount.dfs.core.windows.net/selim/test.csv",
  12. "abfs://storage@127.0.0.1:10000/devstoreaccount1/selim/test.csv",
  13. "http://w...content-available-to-author-only...h.blah"
  14. };
  15. for (String s: inputs) {
  16. Map<String, String> result = null;
  17. Matcher matcher_azurite = pattern_azurite.matcher(s);
  18. if (matcher_azurite.find()){
  19. result = parseMatchResult(matcher_azurite, new int[] {1, 3, -1, 4});
  20. } else {
  21. Matcher matcher_original = pattern_original.matcher(s);
  22. if (matcher_original.find()){
  23. result = parseMatchResult(matcher_original, new int[] {1, 2, 3, 4});
  24. }
  25. }
  26. if (result != null) { // Now print
  27. for (String key : result.keySet()) {
  28. System.out.println("'" + key + "': '" + result.get(key) + "'");
  29. }
  30. System.out.println("----------------");
  31. } else {
  32. System.out.println("No match!");
  33. }
  34.  
  35. }
  36. }
  37. public static Map<String, String> parseMatchResult(Matcher m, int[] indices) {
  38. Map<String, String> res = new HashMap<String, String>();
  39. res.put("fileSystem", m.group(indices[0]));
  40. res.put("accountName", m.group(indices[1]));
  41. res.put("accountSuffix", indices[2] > -1 ? m.group(indices[2]) : "");
  42. res.put("relativePath", m.group(indices[3]));
  43. return res;
  44. }
  45. }
Success #stdin #stdout 0.14s 55188KB
stdin
Standard input is empty
stdout
'fileSystem': 'storage'
'accountSuffix': '.dfs.core.windows.net'
'accountName': 'myaccount'
'relativePath': 'selim/test.csv'
----------------
'fileSystem': 'storage'
'accountSuffix': ''
'accountName': 'devstoreaccount1'
'relativePath': 'selim/test.csv'
----------------
No match!