import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "function (?<name>[a-zA-Z0-9]+)\\s*(?<arguments>\\([^()]*\\)(?::\\s*[^\\{\\}\\s]*)?)\\s*(?<body>\\{[^\\r\\{\\}]*(?:\\{[^\\r\\{\\}]*(?:\\{[^\\r\\{\\}]*(?:\\{[^\\r\\{\\}]*(?:\\{[^\\r\\{\\}]*(?:\\{[^\\r\\{\\}]*\\}[^\\r\\{\\}]*)*\\}[^\\r\\{\\}]*)*\\}[^\\r\\{\\}]*)*\\}[^\\r\\{\\}]*)*\\}[^\\r\\{\\}]*)*\\})(?:;)?";
final String string = "function setupForNoActionsAvailable() {\n"
+ " component.canDelete = jasmine.createSpy('canDelete').and.returnValue(false);\n"
+ " component.canMarkAsBlocked = jasmine.createSpy('canMarkAsBlocked').and.returnValue(false);\n"
+ " component.canMarkAsReBill = jasmine.createSpy('canMarkAsRebill').and.returnValue(false);\n"
+ " component.canMoveToInProgress = jasmine.createSpy('canMoveToInProgress').and.returnValue(false);\n"
+ " }\n\n"
+ "function setupValidConditions() {\n"
+ " component.invoice = {} as any;\n"
+ " component.isReadonly = jasmine.createSpy('isReadonly').and.returnValue(false);\n"
+ " invoiceHelper.canMarkAsReBill = jasmine.createSpy('canMarkAsReBill').and.returnValue(true);\n"
+ " };\n\n"
+ "export function ageInDays(date: Date, now: Date): number {\n"
+ " return Math.trunc(millisecondsToDays(now.getTime() - date.getTime()));\n"
+ "}\n\n"
+ "function millisecondsToDays(milliseconds: number): number {\n"
+ " return (((milliseconds / 1000) / 60) / 60) / 24;\n"
+ "}\n\n"
+ "// Prevent Karma from running prematurely.\n"
+ "__karma__.loaded = function () { };";
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