I'm solving this problem in my own way. I'm trying to split the file path into Drive, folders, and file name, all into an array.
The problem:
String regex = "\\";
String [] divisions = path.split (regex);
This gives me an java.util.regex.PatternSyntaxException. I looked up the wiki and found [\b]
String regex = "[\b]";
String [] divisions = path.split (regex);
This doesn't work. It doesn't throw an exception, nor does it split my file path based on backspace.
Input:
► Enter path --
C:\User\Admin\NekedGaben.jpg
Output:
→ Path = C:\User\Admin\NekedGaben.jpg
→ File name = C:\User\Admin\NekedGaben
→ Extension = .jpg
My questions:
- Why does
"\\"throw an exception, while"[\b]"doesn't? - Why doesn't the
split()split the Path string?
\in regex? (Not"\\", that is a String literal.)[\b]matches a backspace, not a backslash. Why would you ever want to match a backspace? I don't know, I've never needed to. But\bby itself matches a word boundary, and it can't mean that inside a character class, so its meaning arbitrarily changes to backspace.