# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".*tax"
test_str = ("Year\n"
"Qtr\n"
"CASH FLOWS FROM OPERATING ACTIVITIES\n"
"Profit before tax\n"
"Depreciation of property, plant and equipment\n"
"Interest expense\n"
"Unrealised gain on foreign exchange\n"
"Interest income\n"
"Gain on disposal of property, plant and equipment\n"
"Writeback of allowance for impairment losses on trade receivables\n"
"Plant and equipment written off\n"
"Allowance for impairment losses on receivables\n"
"Bad debt written off\n"
"Gain on disposal of an associate\n"
"Share of results of associates\n"
"Operating profit before working capital changes\n"
"Inventories\n"
"Trade receivables\n"
"Other receivables, deposits and prepaid expenses\n"
"Amount owing by an associate\n"
"Trade payables\n"
"Other payables and accrued expenses\n"
"Cash generated from operations\n"
"Taxes paid\n"
"Net cash from operating activities\n"
"CASH FLOWS FOR INVESTING ACTIVITIES\n"
"Interest received\n"
"Additional investment of a subsidiary\n"
"Purchase of property, plant and equipment\n"
"Proceeds from disposal of property, plant and equipment\n"
"Proceeds from disposal of an associate\n"
"Net (placement)/withdrawal of fixed deposits with licensed banks\n"
"Net cash for investing activities\n"
"CASH FLOWS FOR FINANCING ACTIVITIES\n"
"Interest paid\n"
"Dividend paid by the Company\n"
"Dividend paid by a subsidiary to non-controlling interests\n"
"Repayment of term loans\n"
"Payment of lease liabilities\n"
"Net cash for financing activities\n"
"NET INCREASE IN CASH AND CASH EQUIVALENTS\n"
"CASH AND CASH EQUIVALENTS AT BEGINNING OF FINANCIAL YEAR\n"
"EFFECT OF EXCHANGE DIFFERENCES\n"
"CASH AND CASH EQUIVALENTS AT END OF FINANCIAL YEAR\n"
"THE CASH AND CASH EQUIVALENTS COMPRISE\n"
"Cash and bank balances\n"
"Fixed deposits with licensed banks\n"
"Short-term investments\n"
"Less: Fixed deposits pledged with banks\n"
"Less: Fixed deposits with maturity more than 3 months\n"
"Cash and cash equivalents\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