import java.util.*;
import java.util.regex.*;

class Test
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Pattern pattern = Pattern.compile("abfss?://(?:([^@/]*)@(\\d{1,3}(?:\\.\\d{1,3}){3}:\\d+)/([^/]+)|([^/]+)@([^.]+)(\\.[^/]+))(?:/(.+))?");
		String[] inputs = {
		    "abfs://storage@myaccount.dfs.core.windows.net/selim/test.csv",
		    "abfs://storage@127.0.0.1:10000/devstoreaccount1/selim/test.csv"
		};
		for (String s: inputs) {
			Matcher matcher = pattern.matcher(s);
			if (matcher.find()){
				if (matcher.group(5) != null) { // If original URL is found
			        String fileSystem = matcher.group(4); //storage
			        String accountName = matcher.group(5); //myaccount
			        String accountSuffix = matcher.group(6); //.dfs.core.windows.net
			        String relativePath = matcher.group(7); //selim/test.csv
			        System.out.println(s + ":\nfileSystem: " + fileSystem + "\naccountName: " + accountName + "\naccountSuffix: '" + accountSuffix + "'\nrelativePath:" + relativePath + "\n-----");
				} else { // we have an Azurite URL
			        String fileSystem = matcher.group(1); //storage
			        String accountName = matcher.group(3); //devstoreaccount1
			        String accountSuffix = ""; // empty (or do you need matcher.group(2) to get "127.0.0.1:10000"?)
			        String relativePath = matcher.group(7); //selim/test.csv
			        System.out.println(s + ":\nfileSystem: " + fileSystem + "\naccountName: " + accountName + "\naccountSuffix: '" + accountSuffix + "'\nrelativePath:" + relativePath + "\n-----");
				}
			}
		}
	}
}