# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<phase>[0-9]+([,|.]?[0-9]+)?)[\t](?<voltage>[0-9]+([,|.]?[0-9]+)?)[\t](?<fault>[0-9]+([,|.]?[0-9]+)?)[\t](?<PD>[0-9]+([,|.]?[0-9]+)?)"
test_str = ("Fault location:\n"
"Cable-length (m): 266\n"
"Phase Voltage(kV) Fault(m): PD (pC):\n"
"1 11.0 141.452 142.857 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_11kV_2016-08-17-11'04'05.loc\n"
"1 11.0 141.452 190.476 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_11kV_2016-08-17-11'04'19.loc\n"
"1 11.0 141.452 161.905 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_11kV_2016-08-17-11'04'19.loc\n"
"1 11.0 139.673 171.429 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_11kV_2016-08-17-11'04'33.loc\n"
"1 11.0 141.452 152.381 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_11kV_2016-08-17-11'04'33.loc\n"
"1 13.0 140.562 295.238 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'34.loc\n"
"1 13.0 137.004 285.714 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'34.loc\n"
"1 13.0 140.562 238.095 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'34.loc\n"
"1 13.0 142.341 200.000 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'34.loc\n"
"1 13.0 140.562 333.333 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'50.loc\n"
"1 13.0 139.673 314.286 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'50.loc\n"
"3 13.0 136.114 228.571 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'39.loc\n"
"1 13.0 136.114 171.429 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'50.loc\n"
"1 13.0 141.452 276.190 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'06'06.loc\n"
"1 13.0 139.673 180.952 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'06'06.loc\n"
"2 9.0 141.452 142.857 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_9kV_2016-08-17-11'08'58.loc\n"
"2 11.0 136.114 304.762 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'13.loc\n"
"2 11.0 140.562 209.524 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'13.loc\n"
"2 11.0 138.783 285.714 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'30.loc\n"
"2 11.0 140.562 219.048 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'30.loc\n"
"2 11.0 139.673 333.333 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'45.loc\n"
"2 11.0 137.004 238.095 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_11kV_2016-08-17-11'09'45.loc\n"
"2 13.0 140.562 447.619 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'00.loc\n"
"2 13.0 139.673 352.381 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'00.loc\n"
"2 13.0 137.893 323.810 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'00.loc\n"
"2 13.0 134.335 171.429 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'00.loc\n"
"2 13.0 140.562 447.619 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'16.loc\n"
"2 13.0 140.562 419.048 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'16.loc\n"
"2 13.0 138.783 390.476 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'16.loc\n"
"2 13.0 138.783 304.762 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'16.loc\n"
"2 13.0 140.562 200.000 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'16.loc\n"
"2 13.0 140.562 447.619 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'41.loc\n"
"2 13.0 138.783 409.524 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'41.loc\n"
"2 13.0 139.673 361.905 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'41.loc\n"
"2 13.0 137.893 352.381 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L2_13kV_2016-08-17-11'10'41.loc\n"
"3 9.0 139.673 142.857 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_9kV_2016-08-17-11'13'10.loc\n"
"3 11.0 120.101 342.857 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'27.loc\n"
"3 11.0 137.893 171.429 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'27.loc\n"
"3 11.0 139.673 219.048 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'43.loc\n"
"3 11.0 139.673 190.476 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'43.loc\n"
"3 11.0 139.673 304.762 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'57.loc\n"
"3 11.0 139.673 161.905 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_11kV_2016-08-17-11'13'57.loc\n"
"3 13.0 137.893 380.952 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'11.loc\n"
"3 13.0 140.562 352.381 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'11.loc\n"
"3 13.0 139.673 352.381 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'11.loc\n"
"3 13.0 137.893 333.333 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'11.loc\n"
"3 13.0 140.562 200.000 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'11.loc\n"
"3 13.0 139.673 428.571 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'25.loc\n"
"3 13.0 140.562 409.524 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'25.loc\n"
"3 13.0 137.004 323.810 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'25.loc\n"
"3 13.0 136.114 209.524 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'25.loc\n"
"3 13.0 120.101 628.571 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'39.loc\n"
"3 13.0 140.562 314.286 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'39.loc\n"
"3 13.0 137.893 266.667 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L3_13kV_2016-08-17-11'14'39.loc\n"
"1 13.0 139.673 238.095 C:\\Users\\z2066\\Documents\\Munka\\Diagnosztika\\KD 2016\\OWTS\\Gyor regio\\Sopron\\Frankenburg BHTR-Kossuth KTW\\L1_13kV_2016-08-17-11'05'50.loc\n"
"Joints:\n"
"0\n"
"266\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