I created two patterns to compile ls -l
outputs in RegexBuddy, but in Android pattern compile gives me an error. In Java 7 it compiled fine.
The raw patterns are
(^[l,d,-][-,r,w,x]{9})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([0-9]{0,})[\t,\s]{1,}([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\s[0-9]{2}:[0-9]{2})[\t,\s]{1,}(.{1,})
(^[l,d,-][-,r,w,x]{9})[\t,\s]{1,}[0-9]{1,}[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([0-9]{0,})[\t,\s]{1,}(\w{3}\s[0-9]{1,2}[\t,\s]{1,}([0-9]{1,2}:[0-9]{2}|[0-9]{4}))[\t,\s]{1,}(.{1,})
The first is for matching
-rwxr-xr-x 1 doctor users 399 2011-11-11 13:33 shot.s
or
-rwxr-xr-x 1 100 100 399 2011-11-11 13:33 file.txt
The second is for matching
for matching
-rwxr-xr-x 1 doctor users 399 Nov 22 2011 shot.s
or
-rwxr-xr-x 1 100 100 399 Nov 22 13:33 shot.s
In code:
-
private static final Pattern LS_L = Pattern.compile("(^[l,d,-][-,r,w,x]{9})[\\t,\\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\\t,\\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\\t,\\s]{1,}([0-9]{0,})[\\t,\\s]{1,}([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\\s[0-9]{2}:[0-9]{2})[\\t,\\s]{1,}(.{1,})");
-
private static final Pattern LS_L_1 = Pattern.compile("(^[l,d,-][-,r,w,x]{9})[\\t,\\s]{1,}[0-9]{1,}[\\t,\\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\\t,\\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\\t,\\s]{1,}([0-9]{0,})[\\t,\\s]{1,}(\\w{3}\\s[0-9]{1,2}[\\t,\\s]{1,}([0-9]{1,2}:[0-9]{2}|[0-9]{4}))[\\t,\\s]{1,}(.{1,})");
The first one throws
02-24 21:14:21.854: E/AndroidRuntime(3072): Caused by: java.util.regex.PatternSyntaxException: Missing closing bracket in character class near index 219:
02-24 21:14:21.854: E/AndroidRuntime(3072): (^[l,d,-][-,r,w,x]{9})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([0-9]{0,})[\t,\s]{1,}([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\s[0-9]{2}:[0-9]{2})[\t,\s]{1,}(.{1,})
02-24 21:14:21.854: E/AndroidRuntime(3072): ^
02-24 21:14:21.854: E/AndroidRuntime(3072): at java.util.regex.Pattern.compileImpl(Native Method)
02-24 21:14:21.854: E/AndroidRuntime(3072): at java.util.regex.Pattern.compile(Pattern.java:400)
02-24 21:14:21.854: E/AndroidRuntime(3072): at java.util.regex.Pattern.<init>(Pattern.java:383)
02-24 21:14:21.854: E/AndroidRuntime(3072): at java.util.regex.Pattern.compile(Pattern.java:374)
The second one gives me
02-24 21:00:24.166: E/AndroidRuntime(1366): Caused by: java.util.regex.PatternSyntaxException: Missing closing bracket in character class near index 250:
02-24 21:00:24.166: E/AndroidRuntime(1366): (^[l,d,-][-,r,w,x]{9})[\t,\s]{1,}[0-9]{1,}[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([[a-z_][a-z0-9_]{0,30}|[0-9]{1,})[\t,\s]{1,}([0-9]{0,})[\t,\s]{1,}(\w{3}\s[0-9]{1,2}[\t,\s]{1,}([0-9]{1,2}:[0-9]{2}|[0-9]{4}))[\t,\s]{1,}(.{1,})