import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[\\d\\n].*\\n";
final String string = "1\n"
+ "00:00:01.876 --> 00:00:02.709\n"
+ "<v Instructor>We can go back now</v>\n\n"
+ "2\n"
+ "00:00:02.709 --> 00:00:05.042\n"
+ "to our web server checklist.\n\n"
+ "3\n"
+ "00:00:06.410 --> 00:00:08.722\n"
+ "We've already seen better ways to organise our code\n\n"
+ "4\n"
+ "00:00:08.722 --> 00:00:11.545\n"
+ "into reusable pieces with modules,\n\n"
+ "5\n"
+ "00:00:11.545 --> 00:00:13.315\n"
+ "we've seen ways to deal with files,\n\n"
+ "6\n"
+ "00:00:13.315 --> 00:00:15.940\n"
+ "both synchronous and asynchronous,\n\n"
+ "7\n"
+ "00:00:15.940 --> 00:00:16.773\n"
+ "and buffers,\n\n"
+ "8\n"
+ "00:00:16.773 --> 00:00:18.325\n"
+ "both the built-in Node one\n\n"
+ "9\n"
+ "00:00:18.325 --> 00:00:20.380\n"
+ "and the ES6 buffers,\n\n"
+ "10\n"
+ "00:00:20.380 --> 00:00:22.485\n"
+ "and we've seen a way to deal with work";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
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