# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^[\w\s./-]*(?:\s\d+){4}(?:\s\$\d+\.\d+){2}$"
test_str = ("Amount\n"
"2144-PL\n"
"1XL 2XL 3XL\n"
"2144-\n"
"PL Navy Blue 2 2 2 6 $11.50 $69.00\n"
"ETK-2097K-PL PLUS-TOP - BACK BUTTON TUNICS 95% RAYON 5% SPANDEX MADE IN USA\n"
"1XL 2XL 3XL\n"
"Black 2 2 2 6 $12.00 $72.00\n"
"Teal 2 2 2 6 $12.00 $72.00\n"
"ETK-2197-SW-\n"
"1XL 2XL 3XL\n"
"PL ETK-\n"
"2197- H.Grey/Burgu… 2 2 2 6 $14.00 $84.00\n"
"Off-White/Black 1 1 1 3 $14.00 $42.00\n"
"ETK-2143 Tops - 95% RAYON 5% SPANDEX MADE IN USA\n"
"S M L\n"
"Heather Grey 2 2 2 6 $10.50 $63.00\n"
"Royal Blue 2 2 2 6 $10.50 $63.00\n"
"Ruby Red 2 2 2 6 $10.50 $63.00\n"
"ETK2186-GD- Tops-Stripe Solid-95% Rayon 5% Spandex Made in USA\n"
"PL\n"
"1XL 2XL 3XL\n"
"Burgundy/Bur… 2 2 2 6 $11.00 $66.00\n"
"Ivory/Black 2 2 2 6 $11.00 $66.00\n"
"2139 - WP-PL PLUS TOP -95% RAYON 5% SPANDEX MADE IN USA\n"
"1XL 2XL 3XL\n"
"As Shown 2 2 2 6 $9.50 $57.00\n"
"ETK-2228\n"
"S M L\n"
"ETK- \n"
"2228 Off-White/Black 2 2 2 6 $9.50 $57.00\n"
"ETK-2149-PL\n"
"1XL 2XL 3XL\n"
"ETK-\n"
"2149- Taupe 2 2 2 6 $11.50 $69.00\n"
"BACK\n"
"ORDERED\n"
"White 2 2 2 6 $11.50 $69.00\n"
"Sub")
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