import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*tax";
final String string = "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";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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