I have a program that is reading lines of input from a file and must extract information from from each line using a regular expression. Each line is the absolute path to a file or folder in a file system that my application creates. Each line has the following format:
/root/folder1/folder2/folder3
What I need to do is separate the String into an array containing the first part of the path and then the last folder as follows:
["/root/folder1/folder2", "folder3"]
My idea of how to do this was to use a regular expression in conjunction with the java.util.regex.Pattern#split(CharSequence, int) method to split the string using the Pattern while limiting the size of the resultant array. However, since this method matches the pattern to the string starting at the beginning, this method won't work for me. I need something with similar functionality that would check the String for matches starting at the end rather that the beginning. Either that or I need a regular expression wizard to help me cook up a new regular expression to accomplish this.
Right now, I'm using the simple regex "[/]" to split the string.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire