using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^\s*(\d+)?\s?([rwxSTstdcb\-lp?]{10})\s+(\d+)?\s?(\S+)\s+(\S+)\s+([0-9,]+)?\s+(\d+)?\s?([0-9\-]{10}\s+[0-9:]{5}|[A-Z][a-z]{2}\s+[0-9]{1,2}\s+[0-9:]{4,5})\s((?:(?!\s\->\s).)*)(\s\->\s)?(.*)";
string input = @"busybox ls -lain
1769542 -rw------- 1 10163 10163 0 Dec 13 21:06 0.txt
1769543 -rw------- 1 10163 10163 0 Nov 13 21:06 1.txt
1769561 -rw------- 1 10163 10163 0 Feb 13 2016 10.txt
1769562 -rw------- 1 10163 10163 0 Jan 13 2016 11.txt
1769544 -rw------- 1 10163 10163 0 Oct 13 21:06 2.txt
1769545 -rw------- 1 10163 10163 0 Sep 13 21:06 3.txt
1769546 -rw------- 1 10163 10163 0 Aug 13 21:06 4.txt
1769547 -rw------- 1 10163 10163 0 Jul 13 21:06 5.txt
1769550 -rw------- 1 10163 10163 0 Jun 13 2016 6.txt
1769552 -rw------- 1 10163 10163 0 May 13 2016 7.txt
1769559 -rw------- 1 10163 10163 0 Apr 13 2016 8.txt
1769560 -rw------- 1 10163 10163 0 Mar 13 2016 9.txt
toolbox ls -l
drwxr-xr-x root root 1970-03-01 01:33 acct
drwxrwx--- system cache 2016-12-13 10:53 cache
lrwxrwxrwx root root 1969-12-31 16:00 charger -> /sbin/healthd
dr-x------ root root 1970-03-01 01:33 config
lrwxrwxrwx root root 1970-03-01 01:33 d -> /sys/kernel/debug
drwxrwx--x system system 2016-07-06 21:19 data
-rw-r--r-- root root 614 1969-12-31 16:00 default.prop
drwxr-xr-x root root 2016-12-10 00:23 dev
lrwxrwxrwx root root 1970-03-01 01:33 etc -> /system/etc
-rw-r--r-- root root 24061 1969-12-31 16:00 file_contexts
dr-xr-x--- system system 1969-12-31 16:00 firmware
-rw-r----- root root 4158 1969-12-31 16:00 fstab.angler
-rwxr-x--- root root 1142576 1969-12-31 16:00 init
-rwxr-x--- root root 98 1969-12-31 16:00 init.angler.diag.rc
-rwxr-x--- root root 14044 1969-12-31 16:00 init.angler.rc
-rwxr-x--- root root 524 1969-12-31 16:00 init.angler.sensorhub.rc
-rwxr-x--- root root 9729 1969-12-31 16:00 init.angler.usb.rc
-rwxr-x--- root root 941 1969-12-31 16:00 init.environ.rc
toybox ls -la
drwxr-xr-x 20 root root 0 1970-03-01 01:33 .
drwxr-xr-x 20 root root 0 1970-03-01 01:33 ..
drwxr-xr-x 235 root root 0 1970-03-01 01:33 acct
drwxrwx--- 5 system cache 4096 2016-12-13 21:57 cache
busybox ls -la /dev
crw-rw---- 1 system camera 81, 4 1970-01-30 15:02 v4l-subdev3
crw-rw---- 1 system camera 81, 5 1970-01-30 15:02 v4l-subdev4
crw-rw---- 1 system camera 81, 6 1970-01-30 15:02 v4l-subdev5
crw-rw---- 1 system camera 81, 7 1970-01-30 15:02 v4l-subdev6
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx