# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"iPhone [6-7]"
test_str = ("iPhone 7 Plus\n"
"iPad Pro 12.9 2015 iOS15.5 beta 4\n"
"iPhone 11 Pro iOS15.5 beta4\n"
"iPad Pro 10.5 2017\n"
"iPad 9.7 2018 iOS15.5 beta4\n"
"iPhone X \n"
"iPhone 11 Pro Max\n"
"iPad Pro 10.5 2017\n"
"iPad mini 3\n"
"iPhone X\n"
"iPad Pro 12.9 2021\n"
"iPhone 13\n"
"iPhone 11\n"
"iPhone 12 mini\n"
"iPad Pro 12.9 2018\n"
"iPad Pro 11 2018\n"
"iPhone 12\n"
"iPhone X iOS15.5 beta4\n"
"iPad Air 2\n"
"iPhone 8\n"
"iPhone 6\n"
"iPhone XS Max\n"
"iPad mini 4\n"
"iPad Air 3 (2019)\n"
"iPhone SE 2020\n"
"iPhone 11 Pro\n"
"iPhone 12 Pro\n"
"iPad Mini 2019\n"
"iPad 9.7 2018\n"
"iPad 10.2 2020\n"
"iPhone SE\n"
"iPad Air 2\n"
"iPad Air 2022 5th Gen\n"
"iPad Air 2020\n"
"iPad Air 2\n"
"iPad Pro 11 2021\n"
"iPhone SE 2020\n"
"iPhone 6 Plus\n"
"iPad Pro 11 2020\n"
"iPad 10.2 2020\n"
"iPad Pro 10.5 2017\n"
"iPad 10.2\n"
"iPhone XR\n"
"iPad Pro 12.9 2015\n"
"iPad Pro\n"
"iPad Air 2\n"
"iPhone 7\n"
"iPad Mini 2021 6th Gen\n"
"iPad Air 2020\n"
"iPhone 8 Plus\n"
"iPhone 11\n"
"iPad 9.7 2017 5th Gen\n"
"iPhone XS\n"
"iPad Pro 12.9 2020\n"
"iPhone 6S\n"
"iPad Air\n"
"iPhone XS Max\n"
"iPhone SE 2020\n"
"iPhone_11_Pro\n"
"iPhone 5S\n"
"iPhone 8\n"
"iPhone 7 Plus\n"
"iPod Touch 6\n"
"iPad Pro 9.7\n"
"iPhone 12 mini iOS15.5 beta4\n"
"iPhone X\n"
"iPhone 8\n"
"iPhone 6\n"
"iPhone X\n"
"iPhone 13 Pro Max\n"
"iPhone 12 Pro Max\n"
"iPad Air 2 iOS15.5 beta4\n"
"iPhone 6\n"
"iPad mini 4\n"
"iPad Pro 11 2018\n"
"iPad Pro 12.9 2015\n"
"iPhone XR\n"
"iPhone XS\n"
"iPhone XR\n"
"iPhone 7\n"
"iPad Pro 12.9 2017\n"
"iPhone 8\n"
"iPhone 6S\n"
"iPad Pro 12.9 2017\n"
"iPad Pro 12.9\n"
"iPhone X \n"
"iPhone 8 Plus\n"
"iPad Air 3 (2019)\n"
"iPhone 8\n"
"iPhone 12 Pro Max\n"
"iPad Pro 12.9 2015\n"
"iPad mini 4\n"
"iPhone 13 mini\n"
"iPad Air 2\n"
"iPhone 13 Pro\n"
"iPhone 7\n"
"iPhone XS\n"
"iPad 10.2 2021 9th Gen\n"
"iPhone SE 2020\n"
"iPod Touch 7\n"
"iPad Air 2\n"
"iPhone 7 Plus\n"
"iPhone SE 2022\n"
"iPhone 6S Plus\n"
"iPhone 12")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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