# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\b(?!\d)([ELX0-9-])\w{1,}"
test_str = ("S-Buy BL460c G6 E5540 8G 2P Svr\n"
"BL460c G6 X5550 6G 1P Svr\n"
"BL460c G6 E5540 6G 1P Svr\n"
"BL460c G6 E5540 6G 1P Svr\n"
"BL460c G6 E5530 6G 1P Svr\n"
"BL460c G6 L5520 6G 1P Svr\n"
"BL460c G6 E5520 6G 1P Svr\n"
"BL460c G6 E5506 6G 1P Svr\n"
"BL460c G6 E5502 6G 1P Svr\n"
"BL280c G6 L5520 2G LP 1P Svr\n"
"BL280c G6 E5520 2G 1P Svr\n"
"BL280c G6 E5540 2G 1P Svr\n"
"BL280c G6 E5502 2G 1P Svr\n"
"S-Buy BL460c G6 E5540 8G 2P Svr\n"
"S-Buy BL460c G6 E5530 4G 1P Svr\n"
"S-Buy BL460c G6 E5530 4G 1P Svr\n"
"BL2x220c G6 E5540 24G 2P 250GB Svr\n"
"BL2x220c G6 E5530 24G 2P 250GB Svr\n"
"BL2x220c G6 L5530 24G 2P 250GB Svr\n"
"BL2x220c G6 L5520 24G 2P\n"
"BL2x220c G6 E5640 2x2P 24G Svr\n"
"BL2x220c G6 E5630 2x2P 24G Svr\n"
"BL2x220c G6 L5640 2x2P 24G Svr\n"
"BL2x220c G6 Mod0 Svr\n"
"BL280c G6 X5650 6G 1P Svr\n"
"BL280c G6 E5630 4G 1P Svr\n"
"BL280c G6 L5640 4G 1P Svr\n"
"BL280c G6 E5506 2G 1P Svr\n"
"BL620c G7 E7-2860 32G Svr\n"
"BL620c G7 E7-2850 32G Svr\n"
"BL620c G7 E7-2830 32G Svr\n"
"BL680c G7 E7-4860 64G Svr\n"
"BL680c G7 E7-4860 64G Svr\n"
"BL680c G7 E7-4850 64G Svr\n"
"BL680c G7 E7-4830 64G Svr\n")
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