import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\-?\\(.*\\))";
final String string = "363\n"
+ "00:22:09,395 --> 00:22:11,996\n"
+ " Because he did only\n"
+ " meet me the once.\n\n"
+ "364\n"
+ "00:22:11,998 --> 00:22:13,597\n"
+ " Perhaps I could...\n\n"
+ "365\n"
+ "00:22:20,105 --> 00:22:21,772\n"
+ " (CLAMOURING)\n\n"
+ "366\n"
+ "00:22:21,774 --> 00:22:25,009\n"
+ " (INDISTINCT ANNOUNCEMENT\n"
+ " OVER PA)\n\n"
+ "367\n"
+ "00:22:55,340 --> 00:22:58,509\n"
+ " (INDISTINCT ANNOUNCEMENT\n"
+ " OVER PA)\n\n"
+ "368\n"
+ "00:23:10,655 --> 00:23:11,389\n"
+ " SARAH: Excuse me.\n\n"
+ "369\n"
+ "00:23:11,391 --> 00:23:14,225\n"
+ " Were there any men flying\n"
+ " alone on this fligh";
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