I have the following string which i want to use java regex to get the following results.
String s = "/accounts/main/index/page.txt"
String[] result = {"/accounts/", "/accounts/main/", "/accounts/main/index/"};
That is, i would like to get the 'parent directory hierarchy' (This does not have to be a a directory structure).
NOTE: The string "s" is dynamically assigned, so it may be different levels of directory.
I have the following, but i am unsure of how to compile a regex that will return what i want. i know what i want can only return one result, the last entry in the array:
Pattern p = Pattern.compile("^/.+/"); //how do i set up this regex to give me required results.
String s = "/accounts/main/index/page.xhtml";
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group());
}