import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<name>^[A-Za-z\\/()\\'’, -]+)(\\s\\d{2}|\\s[1-9])?\\s?(\\s(?P<d1>-[\\d,]+|[\\d,.]+)\\s(?P<d2>-[\\d,]+|[\\d,.]+))";
final String string = "38\n"
+ "Frontken Corporation Berhad -651020-T Annual Report 2010\n"
+ "STATEMENTS OF FINANCIAL POSITION\n"
+ "AS OF 31 DECEMBER 2010\n"
+ "The Group The Company\n"
+ "Restated Restated\n"
+ "RM RM RM RM RM\n"
+ "ASSETS\n"
+ "Non-Current Assets\n"
+ "Property, plant and equipment 10 178,405,029 116,971,685 112,532,450 190,014 100,755\n"
+ "Prepaid lease payments 11 0 0 0 0 0\n"
+ "Investment in subsidiaries 12 0 0 0 68,192,335 30,903,191\n"
+ "Investment in associates 13 4,494,255 46,538,503 48,192,140 0 22,955,162\n"
+ "Goodwill on consolidation 14 28,311,674 4,724,073 3,749,020 0 0\n"
+ "Intangible assets 15 0 0 0 0 0\n"
+ "Deferred tax assets 16 352,360 0 0 0 0\n"
+ "Current Assets\n"
+ "Inventories 17 10,431,408 8,925,542 9,044,623 0 0\n"
+ "Amount due from contract customers 0 0 668,875 0 0\n"
+ "Trade receivables 18 67,337,237 36,900,201 41,323,668 0 0\n"
+ "Other receivables and prepaid expenses 18 5,125,566 5,285,410 10,169,824 27,841 43,427\n"
+ "Amount owing by subsidiaries 19 0 0 0 45,680,029 43,607,599\n"
+ "Amount owing by associates 13 4,534,039 2,098,465 3,500,059 0 0\n"
+ "Fixed deposits with licensed banks 12,684,190 781,627 758,232 12,000,000 0\n"
+ "Cash and bank balances 21,515,759 12,770,709 10,440,412 1,474,363 200,943\n"
+ "EQUITY AND LIABILITIES\n"
+ "Equity\n"
+ "Share capital 20 101,140,816 72,243,440 69,977,040 101,140,816 72,243,440\n"
+ "Reserves 21 75,102,500 63,104,940 51,689,521 9,444,784 6,607,044\n"
+ "Minority interests 25,901,844 182,232 651,874 0 0\n"
+ "Non-Current Liabilities\n"
+ "Term loans 22 48,314,340 25,265,019 33,200,474 0 0\n"
+ "Hire purchase payables 23 9,867,784 14,596,712 12,091,335 0 0\n"
+ "Deferred tax liabilities 16 4,389,835 3,789,267 3,466,075 0 0\n"
+ "Frontken Corporation Berhad -651020-T Annual Report 2010\n"
+ "STATEMENTS OF FINANCIAL POSITION\n"
+ "AS OF 31 DECEMBER 2010 (CONT’D)\n"
+ "The Group The Company\n"
+ "Restated Restated\n"
+ "RM RM RM RM RM\n"
+ "Current Liabilities\n"
+ "Amount due to contract customers 24 0 47,202 0 0 0\n"
+ "Trade payables 25 20,502,454 12,556,468 19,452,763 0 0\n"
+ "Other payables and accrued expenses 25 16,264,903 12,506,798 18,195,181 310,144 253,253\n"
+ "Amount owing to subsidiaries 19 0 0 0 16,668,838 18,707,340\n"
+ "Amount owing to associates 13 0 117,594 300,858 0 0\n"
+ "Bank overdrafts 26 1,230,283 3,365,362 5,617,839 0 0\n"
+ "Bank borrowings 26 22,132,228 18,367,015 18,471,490 0 0\n"
+ "Deferred income 0 0 19,248 0 0\n"
+ "Hire purchase payables 23 7,249,505 8,223,614 5,906,750 0 0\n"
+ "Tax liabilities 1,095,025 630,552 1,338,855 0 0";
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