import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(cash\\sflows.*activities$|net.*cash.*and cash equivalents?)";
final String string = "CASH FLOWS FROM/(FOR) OPERATING ACTIVITIES\n"
+ "Profit before tax 75,615,413 46,147,364 17,519,528 13,008,793\n"
+ "Depreciation of property, plant and equipment 17,300,505 18,471,479 17,331 21,667\n"
+ "Interest expense 568,006 931,264 56,109 194,461\n"
+ "Allowance for impairment loss on property, plant and equipment 0 49,749 0 0\n"
+ "Unrealised (gain)/loss on foreign exchange -616,303 4,613,657 190,487 95,813\n"
+ "Allowance for impairment losses on amount owing by a subsidiary 0 0 1,242,999 270,000\n"
+ "Allowance for impairment losses on receivables 932,838 71,151 0 0\n"
+ "Bad debt written off 153,130 0 0 0\n"
+ "Inventories written off 0 137,087 0 0\n"
+ "Gain on disposal of an associate -672,207 0 0 0\n"
+ "Property, plant and equipment written off 10,678 506,875 0 0\n"
+ "Share of results in an associate -78,115 51,126 0 0\n"
+ "Interest income -917,220 -844,780 -549,987 -514,753\n"
+ "Gain on disposal of property, plant and equipment -164,099 -11,181 0 0\n"
+ "Writeback of allowance for impairment losses on trade receivables Dividend -10,000 -60,137 0 0\n"
+ "income from subsidiaries 0 0 -23,527,968 -17,028,204\n"
+ "Inventories -379,713 -2,955,410 0 0\n"
+ "Trade receivables -16,590,199 2,180,666 0 0\n"
+ "Other receivables and prepaid expenses -1,492,450 -424,370 -27,867 13,997\n"
+ "Amount owing by an associate 1,330,780 1,698 0 0\n"
+ "Trade payables -826,277 -1,354,959 0 0\n"
+ "Other payables and accrued expenses 3,376,361 9,419,139 1,190,933 956,353\n"
+ "Cash Generated From/(For) Operations 77,541,128 76,930,418 -3,888,435 -2,981,873\n"
+ "Taxes paid -14,218,858 -7,901,643 0 0\n"
+ "CASH FLOWS (FOR)/FROM INVESTING ACTIVITIES\n"
+ "Repayment from subsidiaries 0 0 1,514,464 9,000,836\n"
+ "Purchase of property, plant and equipment -7,492,297 -20,152,154 -3,689 -830\n"
+ "Dividend received from subsidiaries 0 0 21,039,335 14,800,304\n"
+ "Additional investment/acquisition of subsidiaries (Note 11) -7,133,082 -13,273,927 -7,133,082 -13,273,927\n"
+ "Proceeds from disposal of an associate 2,496,557 0 0 0\n"
+ "Proceeds from disposal of property, plant and equipment 1,077,256 138,530 0 0\n"
+ "Withdrawal of short-term investments 0 2,197,876 0 0\n"
+ "Net withdrawal/(placement) of fixed deposits with licensed banks 2,992,578 -1,833,200 1,104,683 -31,986\n"
+ "Interest received 917,220 844,780 549,987 514,753\n"
+ "CASH FLOWS FOR FINANCING ACTIVITIES\n"
+ "Decrease in amount owing to subsidiaries (Note 29(a)) 0 0 591,745 -5,754,789\n"
+ "Repayment of term loans (Note 29(a)) -16,712,117 -7,883,738 -2,037,933 -2,090,577\n"
+ "Interest paid -568,006 -931,264 -56,109 -194,461\n"
+ "Dividend paid by the Company (Note 26) -7,335,779 -5,239,843 -7,335,779 -5,239,843\n"
+ "Dividend paid by a subsidiary to non- controlling interests -2,626,027 -1,984,852 0 0\n"
+ "Drawdown of term loans (Note 29(a)) 0 7,901,920 0 0\n"
+ "Payment of hire purchase payables (Note 29(a)) -544,511 -251,063 0 0\n"
+ "NET INCREASE/(DECREASE) IN CASH AND CASH EQUIVALENTS 28,394,062 28,561,840 4,345,187 -5,252,393\n"
+ "Effect of exchange rate changes 293,086 -6,376,820 8,004 -374,697\n"
+ "CASH AND CASH EQUIVALENTS AT BEGINNING OF YEAR 120,252,919 98,067,899 9,757,017 15,384,107\n"
+ "CASH AND CASH EQUIVALENTS AT END OF YEAR (Note 29(b)) 148,940,067 120,252,919 14,110,208 9,757,017";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html