import re
regex = re.compile(r"(\/.*:)")
test_str = ("/system:\n"
"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\n"
"/system/app:\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 AnalyticsCore\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 AntHalService\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 AntiSpam\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 AppIndexProvider\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 ApplicationsProvider\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 AutoTest\n"
"drwxr-xr-x 0 0 2017-03-30 20:52 Bluetooth")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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 Python, please visit: https://docs.python.org/3/library/re.html