import re
regex = re.compile(r"(-- iOS 8\.2 --)\G|.(?:iPhone 4s.\((.*?)\))")
test_str = ("== Device Types ==\n"
"iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)\n"
"iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)\n"
"iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)\n"
"iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)\n"
"iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)\n"
"iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)\n"
"iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)\n"
"iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)\n"
"Resizable iPhone (com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone)\n"
"Resizable iPad (com.apple.CoreSimulator.SimDeviceType.Resizable-iPad)\n"
"== Runtimes ==\n"
"iOS 8.1 (8.1 - 12B411) (com.apple.CoreSimulator.SimRuntime.iOS-8-1)\n"
"iOS 8.2 (8.2 - 12D508) (com.apple.CoreSimulator.SimRuntime.iOS-8-2)\n"
"== Devices ==\n"
"-- iOS 8.1 --\n"
" iPhone 4s (F05C1130-5F17-483C-8545-41DB60BD6729) (Shutdown)\n"
"-- iOS 8.2 --\n"
" iPhone 4s (F05C1130-5F17-483C-8545-41DB60BD6729) (Shutdown)\n"
" iPhone 5 (6A9974F3-4C46-4583-9D74-A1083E76CCB9) (Shutdown)\n"
" iPhone 5s (89547F56-69D0-4696-98F5-9C4AF58BEC08) (Shutdown)\n"
" iPhone 6 Plus (AD19FA1E-4091-44D7-900E-E9BDF6E22460) (Shutdown)\n"
" iPhone 6 (6D639171-D599-43E9-BFCF-CD2765CE4DEE) (Booted)\n"
" iPad 2 (C8A1DF07-27D9-467F-BBCC-C76695C81BD0) (Shutdown)\n"
" iPad Retina (3ED6ED7E-D173-4C50-88EB-AB2F1CCA30D0) (Shutdown)\n"
" iPad Air (9FF89D26-305F-4BBF-8BC6-90BB2AE4C424) (Shutdown)\n"
" Resizable iPhone (C4BC5922-316C-4176-96FE-8FE2B066C1FD) (Shutdown)\n"
" Resizable iPad (DCF07107-4FD4-4B77-A531-0B652F6C1C61) (Shutdown)\n"
"-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-3 --\n"
" iPhone 4s (F88A4DF6-3B81-445D-A296-73CC69CE7FE6) (Shutdown) (unavailable, runtime profile not found)\n"
" iPhone 5 (ED535FC5-34CE-43B4-ABCA-C57093F7D8FF) (Shutdown) (unavailable, runtime profile not found)\n"
" iPhone 5s (7CFE4925-328E-483E-B137-996520446291) (Shutdown) (unavailable, runtime profile not found)\n"
" iPhone 6 Plus (1BAD21C1-33B8-49A1-90F1-6C9C4FDDDE4B) (Shutdown) (unavailable, runtime profile not found)\n"
" iPhone 6 (3EDA5D17-001B-49CD-83A6-7E1A3926CB28) (Shutdown) (unavailable, runtime profile not found)\n"
" iPad 2 (EA7BBF7B-CFA1-49A6-A84D-471F31E832B8) (Shutdown) (unavailable, runtime profile not found)\n"
" iPad Retina (52B69DBB-352A-49C9-9B56-8EEB463DD023) (Shutdown) (unavailable, runtime profile not found)\n"
" iPad Air (CF60978F-52EF-4E12-8B63-02BEA30D1702) (Shutdown) (unavailable, runtime profile not found)\n"
" Resizable iPhone (903870E3-FF55-48BB-953F-26CCBAFE5E45) (Shutdown) (unavailable, runtime profile not found)\n"
" Resizable iPad (C447F468-2FCE-4731-8CAA-86922F8002CC) (Shutdown) (unavailable, runtime profile not found)")
match = regex.search(test_str)
if match:
print(f"Match 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