# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(Port of Registry\s*:\s*[a-z]{1,}\s*)"
test_str = ("ATTN : SNP TEAM\n"
" \n"
"Kindly be noted that recent deal was just failed due to late sub lifting by the sellers. Therefore still we can\n"
"develop for sale the following panamax bulk carrier from very close bank:-\n"
"(sellers are ‘Shinhan Capital’ and I have done many deals with them since last 10 years.)\n"
" \n"
"M/V DAEBO TRADER\n"
"==============\n"
"Type : Bulk Carrier\n"
"IMO NO. : 9230153\n"
"Flag : KOREA\n"
"Port of Registry : JEJU\n"
"Class : KR\n"
"Built : 2002 / Namura Shipbuilding, Japan\n"
"DWT : 73,870 mt on 13.962 m Draft\n"
"GRT / NRT : 39,056 / 25,246\n"
"LOA : 224.89 m\n"
"LBP : 215.00 m\n"
"Draught : 13.95 m\n"
"Beam : 32.20 m\n"
"M/E : MAN B&W 7S50MC-C8.1\n"
"Grain Capacity : 89,000 cu.m\n"
"Side-rolling hatches, Hydraulically operated, 7HO/7HA\n"
" \n"
"(All details are given in good faith but without guarantee.)\n"
" \n"
"She is laid up in Yeosu/Korea.\n"
"Holding fuller details and it is at your disposal.\n"
"Inviting best offers.\n"
" \n"
"Thanks & Best Regards\n"
"Danny, Park\n"
"설명: 설명: 설명: 훼어브릿지로고(영문)가로\n"
"FAIRBRIDGE GLOBAL INC.\n"
"Tel : +82 2 553 5190\n"
"Dir : +82 2 722 5191\n"
"Mob: +82 10 5299 1126\n"
"MSN: dannypark78@hotmail.com\n"
"Mail: snp@fairbridge.co.kr")
matches = re.finditer(regex, test_str, re.IGNORECASE)
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