# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r",?\s?(\"[^\"]*,[^\"]*\"|[^\",]*)"
test_str = ("St. Lawrence County,NY,,2,,Attainment Plan/Maintenance Plan,37,,1852,Nonattainment,,,,11922,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,2,,5,,0,0,,,,,,,,,,,,,,11922,,,,St. Lawrence County,4700,NY,NY,SO2.2010.St_Lawrence_Co,SO2.2010.St_Lawrence_Co.NY,,,,,,,,,,\n"
"Howard County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1853,Nonattainment,,,,281,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,281,,,,Howard County,4710,TX,TX,SO2.2010.Howard_Co,SO2.2010.Howard_Co.TX,,,,,,,,,,\n"
"Hutchinson County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1854,Nonattainment,,,,14593,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,14593,,,,Hutchinson County,4720,TX,TX,SO2.2010.Hutchinson_Co,SO2.2010.Hutchinson_Co.TX,,,,,,,,,,\n"
"Navarro County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1855,Nonattainment,,,,1593,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,1593,,,,Navarro County,4730,TX,TX,SO2.2010.Navarro_Co,SO2.2010.Navarro_Co.TX,,,,,,,,,,\n"
"Giles County,VA,,3,,Attainment Plan/Maintenance Plan,37,,1856,Nonattainment,,,,183,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,3,,5,,0,0,,,,,,,,,,,,,,183,,,,Giles County,4740,VA,VA,SO2.2010.Giles_Co,SO2.2010.Giles_Co.VA,,,,,,,,,,\n"
"New Madrid County,MO,,7,,Attainment Plan/Maintenance Plan,37,,1851,Nonattainment,,,,2,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,7,,5,,0,0,,,,,,,,,,,,,,2,,,,New Madrid County,4690,MO,MO,SO2.2010.New_Madrid_Co,SO2.2010.New_Madrid_Co.MO,,,,,,,,,,\n"
"Henderson-Webster Counties,KY,,4,,Attainment Plan/Maintenance Plan,37,,1850,Nonattainment,,,,6932,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,4,,5,,0,0,,,,,,,,,,,,,,6932,,,,Henderson-Webster Counties,4680,KY,KY,SO2.2010.Henderson_Webster_Cos,SO2.2010.Henderson_Webster_Cos.KY,,,,,,,,,,\n"
"Whatcom County,WA,,10,,Attainment Plan/Maintenance Plan,37,,1857,Nonattainment,,,,32,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,10,,5,,0,0,,,,,,,,,,,,,,32,,,,Whatcom County,4750,WA,WA,SO2.2010.Whatcom_Co,SO2.2010.Whatcom_Co.WA,,,,,,,,,,")
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