import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:^|\\n)\\d+\\n[\\d\\:\\,\\s\\->]+";
final String string = "1\n"
+ "00:00:00,000 --> 00:00:16,700\n"
+ "to use 2 languages.\n\n"
+ "2\n"
+ "00:00:16,700 --> 00:00:19,600\n"
+ "I was saying that we are going to use 2 languages\n\n"
+ "3\n"
+ "00:00:19,600 --> 00:00:24,700\n"
+ "...I myself will continue to speak because of time";
final String subst = "\\n";
final Pattern pattern = Pattern.compile(regex);
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