# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".*nexus.*"
test_str = ("Xiaomi Pocophone F1\n"
"Google Pixel 4 XL\n"
"Samsung Galaxy S22 Plus 5G\n"
"Samsung Galaxy Tab A 9.7\n"
"Samsung Tab E\n"
"Huawei Y9 2019\n"
"Samsung Galaxy Tab S8\n"
"Samsung Tab E 9.6\n"
"Samsung Galaxy S8\n"
"Google Pixel 2\n"
"Samsung Galaxy A10\n"
"Samsung Galaxy A51\n"
"LG Q6\n"
"Huawei P9\n"
"Samsung Galaxy A71 5G\n"
"ZTE Axon 7\n"
"Samsung Galaxy S20 Ultra\n"
"LG Q Stylo 4\n"
"Moto Z2 Force\n"
"Samsung Galaxy S21 5G\n"
"ZTE Axon 7\n"
"Google Pixel 3a XL\n"
"Samsung Galaxy S6 Edge\n"
"Sony Xperia XZ\n"
"OnePlus 9 Pro\n"
"Samsung Galaxy S8+\n"
"Samsung Galaxy Note 20 Ultra 5G\n"
"LG V30\n"
"Motorola Moto Z\n"
"OnePlus 5T\n"
"Samsung Galaxy S6 Edge\n"
"Samsung Galaxy M20\n"
"OnePlus 9\n"
"Samsung Galaxy A02\n"
"Samsung Galaxy S7\n"
"Mason D450B\n"
"Samsung Galaxy S22 5G\n"
"Google Pixel 4a\n"
"Samsung Galaxy Tab A 10.1 2016\n"
"Samsung Galaxy Note 8\n"
"Asus Google Nexus 7 (2013)\n"
"Samsung Galaxy A30\n"
"Google Pixel 4 XL\n"
"Vivo X21\n"
"Samsung Galaxy S10e\n"
"Samsung Galaxy S10\n"
"Samsung Galaxy S21 Plus 5G\n"
"OnePlus Nord N200 5G\n"
"Google Pixel 4 XL\n"
"Samsung Galaxy A9 2018\n"
"Samsung Galaxy A51\n"
"Motorola Moto G Stylus 2021\n"
"Google Pixel 4\n"
"Huawei Honor 9\n"
"Samsung Galaxy S6 Edge+\n"
"Samsung Galaxy A20e\n"
"Mason G450A1\n"
"Xiaomi Mi MIX 2\n"
"Samsung Galaxy Tab A7\n"
"Google Pixel 5a\n"
"Google Pixel 6 Pro\n"
"Samsung Galaxy A21\n"
"Samsung Galaxy Note 20 5G\n"
"HTC One A9\n"
"Huawei Honor 8\n"
"Samsung Galaxy S6 Edge+\n"
"Google Pixel 2 XL\n"
"Samsung Galaxy S8+\n"
"Nokia 7.1\n"
"Samsung Galaxy S20 Plus\n"
"Samsung Galaxy A3 2017\n"
"LG K10\n"
"HTC Desire 12\n"
"Samsung Galaxy A5 (2017)\n"
"Huawei P30 Lite\n"
"LG V40\n"
"OnePlus 6T\n"
"Google Pixel 3 XL\n"
"Google Pixel C\n"
"Motorola Moto G5 Plus\n"
"Samsung Galaxy S20\n"
"Samsung Galaxy A31\n"
"Google Pixel 3\n"
"Sony Z5 Premium\n"
"Sony Xperia Z1\n"
"LG Phoenix 2\n"
"Samsung Galaxy Tab S6\n"
"Samsung Galaxy J7 2016\n"
"Honeywell CK65\n"
"Samsung Galaxy A5\n"
"HTC 10\n"
"Sony Xperia 10\n"
"Google Pixel 3a XL\n"
"Sony Xperia 5\n"
"Samsung Galaxy A6 2018\n"
"Samsung Galaxy S9\n"
"Samsung Galaxy S5\n"
"Google Pixel XL\n"
"LG G7 Thinq\n"
"Motorola Moto X Play\n"
"Huawei P30 Lite\n"
"Samsung Galaxy S10+\n"
"Samsung Galaxy Tab S2\n"
"Samsung Galaxy Tab S8 Plus\n"
"LG K30\n"
"LG V30+ Thinq\n"
"Samsung Galaxy A80\n"
"OnePlus 3T\n"
"Samsung Galaxy S22 Ultra 5G\n"
"Huawei Mate 9\n"
"Samsung Galaxy Note 20 Ultra 5G\n"
"OnePlus 3\n"
"OnePlus 7 Pro\n"
"Nokia 8\n"
"Samsung Galaxy Z Fold 2 5G\n"
"OnePlus 6\n"
"Samsung Galaxy Tab S5e\n"
"Samsung Galaxy A50\n"
"Samsung Galaxy S21 Ultra 5G\n"
"LG Stylo 6\n"
"Google Pixel 3\n"
"Sony Xperia Z3 Compact\n"
"Xiaomi MI 6\n"
"LG V20\n"
"Google Pixel 5\n"
"Motorola Moto G Power (2021)\n"
"Lenovo Tab 3 Pro\n"
"Motorola Moto G6\n"
"Essential PH-1\n"
"Samsung Galaxy Note 9\n"
"Samsung Galaxy S10e\n"
"Samsung Galaxy A8 2018\n"
"Samsung Galaxy A10e\n"
"Samsung Galaxy Note 5\n"
"Samsung Galaxy Fold 5G\n"
"Samsung Galaxy Note 4\n"
"Samsung Galaxy S21 5G\n"
"Samsung Galaxy Tab S7\n"
"Motorola One Vision\n"
"Samsung Galaxy Note 10+\n"
"LG G8 ThinQ\n"
"Amazon Kindle Fire HD 8\n"
"Motorola Moto G7\n"
"Samsung Galaxy Tab S7 Plus\n"
"Samsung Galaxy Z Flip\n"
"LG G6\n"
"Samsung Galaxy S7 Edge\n"
"Samsung Galaxy Tab S8 Ultra\n"
"Google Pixel 6 Pro\n"
"Huawei P10\n"
"Huawei P20\n"
"Samsung Galaxy Note 5\n"
"OnePlus 8 Pro\n"
"Amazon Kindle Fire HD 8 (2020)\n"
"Samsung Galaxy S6\n"
"Xiaomi Redmi Note 9\n"
"Motorola Nexus 6\n"
"Motorola Moto G6 Plus\n"
"Vivo V9\n"
"Samsung Galaxy Tab S4\n"
"Samsung Galaxy S10\n"
"Motorola Moto X (2nd gen)\n"
"Amazon Kindle Fire HD 10 (2019)\n"
"OnePlus 7T\n"
"OnePlus 8\n"
"Samsung Galaxy Xcover 3\n"
"Xiaomi Redmi 9\n"
"Sony Xperia XZ1\n"
"ZTE Blade V7 lite\n"
"Huawei P30 Pro\n"
"Samsung Galaxy Tab S4 10.5\n"
"Google Pixel 6\n"
"Amazon Kindle Fire HD 7\n"
"Huawei P20 Pro\n"
"Motorola Moto Z Play\n"
"Huawei Mate 10 Pro\n"
"OnePlus 5\n"
"Google Pixel 3 XL\n"
"Google Pixel 3a\n"
"Samsung Galaxy Note 10\n"
"Samsung Galaxy Tab S3")
matches = re.finditer(regex, test_str, re.MULTILINE | re.IGNORECASE)
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