import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<quotes>\"|''')\n"
+ "(?P<names1>.*?)\n"
+ "\\b[Vv]\\b\n"
+ "(?P<names2>.*?)\n"
+ "\\s*\\[?\n"
+ "\\s*\\b(?P<day>[1-9]|[12]\\d|3[01])\\b\n"
+ "\\s*\\b(?P<month>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\w*)\\b\n"
+ "\\s*\\b(?P<year>\\d{4})\\b\n"
+ "\\s*\\]?\n"
+ "\\1\n";
final String string = "1 \"R J BRUCE & OTHERS V B J & W L A EDWARDS And Ors CA CA19/02 27 February 2003\",\n"
+ "2 \"H v DIRECTOR OF PROCEEDINGS [2014] NZHC 1031 [16 May 2014]\",\n"
+ "3 '''GREGORY LANCASTER AND JOHN HENRY HUNTER V CULLEN INVESTMENTS LIMITED AND ERIC JOHN WATSON CA CA51/03 26 May 2003'''\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.COMMENTS);
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