import re
regex = re.compile(r"(?P<line1>^(\w|\s+\w)[a-z]\w+[^\d:]*$)\n(\s+)?(?P<line2>(([A-Za-z ,()]+)|(.*)?(\(\w+.*\)))(\s+)?((-[\d,]+|[\d,]+)\s(\s+)?(-[\d,]+|[\d,]+).*))", flags=re.MULTILINE)
test_str = ("Frontken Corporation Berhad -651020-T 55\n"
"ANNUAL REPORT 2016\n"
"statements Of cash Flows \n"
"For The Year Ended 31 December 2016\n"
" The Group The company \n"
" 2016 2015 2016 2015\n"
" Rm Rm Rm Rm\n"
"CASH FLOWS FROM/ (FOR) OPERATING ACTIVITIES \n"
"Profit before tax 33,344,738 15,998,086 6,154,262 178,853\n"
"Adjustments for: \n"
" Depreciation of property, plant \n"
" and equipment 17,193,402 18,132,726 24,047 23,816\n"
" Interest expense 1,146,951 1,494,353 340,916 555,514\n"
" Allowance for impairment loss \n"
" on plant and equipment 51,841 1,713,303 0 0 \n"
" Unrealised (gain)/loss on \n"
" foreign exchange -1,428,927 -2,918,303 -14,377 2,217,362\n"
" Allowance for impairment losses \n"
" on amount owing by a subsidiary 0 0 1,476,080 0 \n"
" Allowance for impairment losses \n"
" on receivables 133,461 294,518 0 0 \n"
" Impairment loss on investment \n"
" in subsidiaries 0 0 0 441,468\n"
" Inventories written down to net \n"
" realisable value 0 52,272 0 0 \n"
" Inventories written off 492,724 146,823 0 0 \n"
" (Gain)/Loss on dissolution of a subsidiary -719,412 0 107,770 0 \n"
" Property, plant and equipment written off 411,330 2,919,978 0 0 \n"
" Share of results in associates 108,525 -25,186 0 0 \n"
" Loss on disposal of investment in \n"
" a subsidiary 0 1,870,011 0 323,468\n"
" Interest income -769,559 -780,339 -593,490 -879,365\n"
" Loss/(Gain) on disposal of property, \n"
" plant and equipment 68,214 -6,669 0 0 \n"
" Writeback of allowance for impairment \n"
" losses on trade receivables -1,196 -717,433 0 0 \n"
" dividend income from subsidiaries 0 0 -10,313,095 -5,084,439 \n"
"Operating Profit/(Loss) Before\n"
" Working Capital Changes 50,032,092 38,174,140 -2,817,887 -2,223,323\n"
"The accompanying Notes form an integral part of these Financial Statements.\n"
"56 Frontken Corporation Berhad -651020-T\n"
"ANNUAL REPORT 2016\n"
"statements Of cash Flows \n"
"For The Year Ended 31 December 2016 (cont’d)\n"
" The Group The company \n"
" 2016 2015 2016 2015\n"
" Rm Rm Rm Rm\n"
"Decrease/(Increase) in: \n"
" Inventories 752,679 -968,022 0 0 \n"
" Amount owing by a contract \n"
" customer 0 1,837,000 0 0 \n"
" Trade receivables -5,097,661 27,182,094 0 0 \n"
" Other receivables and \n"
" prepaid expenses 1,172,632 -733,496 -23,556 25,634\n"
" Amount owing by associates -3,771 28,485 0 0 \n"
"Increase/(Decrease) in: \n"
" Trade payables -11,074,834 -8,029,512 0 0 \n"
" Other payables and accrued expenses 15,324,322 -4,748,405 -138,524 -455,447 \n"
"Cash Generated From/\n"
" (For) Operations 51,105,459 52,742,284 -2,979,967 -2,653,136 \n"
"Taxes paid -6,681,818 -8,242,591 0 0 \n"
"Net Cash From/(For) \n"
" Operating Activities 44,423,641 44,499,693 -2,979,967 -2,653,136 \n"
"CASH FLOWS (FOR)/FROM INVESTING ACTIVITIES \n"
"Repayment from subsidiaries 0 0 8,435,398 5,252,690\n"
"Purchase of property, plant and \n"
" equipment -27,730,908 -7,196,780 -2,929 -2,849\n"
"dividend received from subsidiaries 0 0 4,268,995 4,634,439\n"
"Additional investment/acquisition \n"
" of subsidiaries (Note 11) -7,399,144 -6,862,024 -7,399,142 -5,103,100\n"
"Net cash outflow on disposal of a \n"
" subsidiary (Note 11) 0 -785,413 0 0 \n"
"Proceeds from disposal of property, plant\n"
" and equipment 188,769 77,955 0 -\n"
"proceeds from disposal of a subsidiary 0 0 0 85,304\n"
"Short-term investment -2,243,001 0 0 0 \n"
"Net withdrawal/(placement) of fixed\n"
" deposits with licensed banks 1,377,357 6,600,196 -32,254 6,967,605\n"
"Interest received 769,559 780,339 593,490 879,365 \n"
"Net Cash (For)/From \n"
" Investing Activities -35,037,368 -7,385,727 5,863,558 12,713,454\n"
"The accompanying Notes form an integral part of these Financial Statements.\n"
"Frontken Corporation Berhad -651020-T 57\n"
"ANNUAL REPORT 2016\n"
"statements Of cash Flows \n"
"For The Year Ended 31 December 2016 (cont’d)\n"
" The Group The company \n"
" note 2016 2015 2016 2015\n"
" Rm Rm Rm Rm\n"
"CASH FLOWS (FOR)/FROM FINANCING ACTIVITIES \n"
"decrease in amount owing to\n"
" subsidiaries 0 0 -1,680,840 -2,275,689\n"
"Treasury shares acquired -64,491 -33,751 -64,491 -33,751\n"
"proceeds from issuance of shares 0 7,564,855 0 7,564,855\n"
"repayment of term loans -30,567,224 -878,769 -1,936,843 -1,810,825\n"
"Interest paid -1,146,951 -1,494,353 -340,916 -555,514\n"
"dividend paid by a subsidiary to non-\n"
" controlling interests -2,151,371 -1,806,882 0 0 \n"
"Drawdown of term loans 16,146,540 4,401,620 0 -\n"
"payment of hire purchase payables -689,599 -1,506,234 0 0 \n"
"net cash (For)/From\n"
" Financing Activities -18,473,096 6,246,486 -4,023,090 2,889,076 \n"
"net (Decrease)/increase \n"
" in cash And cash \n"
" Equivalents -9,086,823 43,360,452 -1,139,499 12,949,394 \n"
"Effect of exchange rate changes 2,037,383 9,181,739 63,094 116,833 \n"
"cAsH AnD cAsH EQUiVALEnTs \n"
" AT BEGinninG OF YEAR 105,117,339 52,575,148 16,460,512 3,394,285 \n"
"cAsH AnD cAsH EQUiVALEnTs \n"
"*\n"
" AT EnD OF YEAR 98,067,899 105,117,339 15,384,107 16,460,512\n"
"Note : During the financial year, the Group and the Company acquired property, plant and equipment at an aggregate cost \n"
"of RM27,900,908 and RM2,929 -2015 : RM7,196,780 and RM2,849, respectively, of which RM170,000 and NIL \n"
"-2015 : NIL and NIL, respectively, was acquired under hire-purchase arrangements. \n"
"*\n"
" The Group The company \n"
" 2016 2015 2016 2015\n"
" Rm Rm Rm Rm\n"
"cAsH AnD cAsH EQUiVALEnTs \n"
"Cash and bank balances 88,745,512 94,486,988 9,993,581 14,460,511\n"
"Fixed deposits with licensed banks 5,872,035 15,310,588 1,072,697 3,040,444\n"
"Short-term investments - unit trust 6,753,232 0 5,390,526 0 \n"
" 101,370,779 109,797,576 16,456,804 17,500,955\n"
"Less: Fixed deposits pledged with banks -3,205,263 -4,680,237 -1,072,697 -1,040,443\n"
"Less: Fixed deposits with maturity \n"
" period more than 3months -97,617 0 0 0 \n"
"Cash and cash equivalents 98,067,899 105,117,339 15,384,107 16,460,512\n"
"The accompanying Notes form an integral part of these Financial Statements.")
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