import re
regex = re.compile(r"^(?:[^,\r\n]*,){6}.*\r?\n(?:[^,\r\n]*,){9}.*(?:\r?\n(?!(?:[^,\r\n]*,){6}.*\r?\n(?:[^,\r\n]*,){9}).*)*", flags=re.MULTILINE)
test_str = ("LB,32736,0,T,NRJ.POMPES_BACHE.PUISSANCE_ELEC_INST,20190811T080000.000Z,20190811T194400.000Z\n"
"TR,NRJ.POMPES_BACHE.PUISSANCE_ELEC_INST,0,65535,1,1,,0,0,2\n"
"20190811T080000.000Z,0.00800000037997961,192\n"
"20190811T080100.000Z,0.008999999612569809,192\n"
"20190811T080200.000Z,0.008999999612569809,192\n"
"LB,32734,0,T,NRJ.POMPES_BACHE.PUISSANCE_ELEC_CPT,20190811T080000.000Z,20190811T201200.000Z\n"
"TR,NRJ.POMPES_BACHE.PUISSANCE_ELEC_CPT,0,65535,1,1,,0,0,2\n"
"20190811T080000.000Z,0.6743068099021912,192\n"
"20190811T080100.000Z,0.6744459867477417,192\n"
"20190811T080200.000Z,0.6745882630348206,192\n"
"20190811T080300.000Z,0.6747232675552368,192\n"
"20190811T080400.000Z,0.6748600006103516,192\n"
"20190811T080500.000Z,0.6749916672706604,192\n"
"20190811T080600.000Z,0.6751362681388855,192\n\n"
"1,2,3,4,5,6,7\n"
"1,2,3,4,5,7,7,8,9,10\n"
"1,2,3\n"
"1,2,3,4,5,6,7\n"
"1,2,3,4,5,7,7,8,9,10\n"
"1,2,3")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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