# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(E)(?=\d{4})"
test_str = ("Test String\n"
"2571130,733 5533151,436 E5015 6 16 E5015 16 \n"
"2576626,674 5531614,498 E5090 6 16 E50900 16 \n"
"2576614,102 5531577,319 E50/17 1 16 E50/17 16 \n"
"2567054,088 5538296,751 E5018 6 16 ;E5018 16 \n"
"2576606,227 5531589,142 E5070 6 16 Ei5070 16 \n"
"2584724,341 5502054,434 R7070 6 17 F7070 16 \n"
"2584735,918 5502107,131 R7014 6 17 R7014 16")
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