import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(.*:[\\w]{2} )(.*)";
final String string = "drwxr-xr-x 0 0 2017-04-01 09:15 app\n"
+ "drwxr-xr-x 0 2000 2017-03-30 20:53 bin\n"
+ "-rw-r--r-- 0 0 10911 2017-04-11 18:53 build.prop\n"
+ "drwxr-xr-x 0 0 2017-04-01 09:14 data-app\n"
+ "drwxr-xr-x 0 0 2017-06-05 22:01 etc\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:53 fonts\n"
+ "drwxr-xr-x 0 0 2017-04-17 20:39 framework\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:53 lib\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:53 lib64\n"
+ "drwxrwx--- 0 0 2017-03-30 20:52 lost+found\n"
+ "drwxr-xr-x 0 0 2017-03-31 05:58 media\n"
+ "drwxr-xr-x 0 0 2017-04-01 09:16 priv-app\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:54 rfs\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:54 spaces\n"
+ "drwxr-xr-x 0 0 2017-03-30 20:54 usr\n"
+ "drwxr-xr-x 0 2000 2017-03-30 20:54 vendor\n"
+ "drwxr-xr-x 0 2000 2017-03-30 20:54 xbin";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html