I am trying unsuccessfully to use Java to match a line so I can use particular parts of the line. The String line is:
String line = "-rw-rw-r-- 1 sherman sherman 0 Feb 14 12:17 nonpedalSwing";
I am using Pattern and Matcher. This is an example of how I want to seperate the line so I can use sub 2, sub 3, and sub 5.
String Pattern = "^(-rw-rw-r-- 1 sherman sherman 0)(Feb)(14)( 12:17 )(nonpedalSwing)";
This does not work for me:
String Pattern = "^(-\\w+-\\w+-\\w--\\s\\d\\s\\w+\\s\\w+\\s+\\d\\s)(\\w+)(\\s)(\\d+)(\ \s\\d+:\\d+\\s)(\\w+)";
At the end of this message is the code I am playing with.
How would you do it?
Also this part of the pattern which is used to match the file permissions seems a bit fragile:
For example: if the permissions changed from -rw-rw-r-- to -r--r--r-- your pattern would not match. A safer pattern might be something like:or
Thank you to everone and I really appreciate the time you all took to answer this. I have been using PERL regex since 1993 so I thought this would be an easy step to develop this in Java. Came as a surprise when I couldn't. I am retired and working at the Home Depot and using my off time to improve myself. Again thanks to all. Now how do I mark this as solved and closed?