import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(,\\d{3}$)";
final String string = "1\n"
+ "00:00:06,000 --> 00:00:12,074\n"
+ "- = www.OpenSubtitles.org = -\n\n"
+ "2\n"
+ "00:01:35,623 --> 00:01:38,208\n"
+ "Apollo Três aqui.\n"
+ "Houston, você pode me copiar?\n\n"
+ "3\n"
+ "00:01:39,168 --> 00:01:41,378\n"
+ "Apollo Três, aqui é Houston.\n"
+ "Voce me ouve\n\n"
+ "4\n"
+ "00:01:41,503 --> 00:01:43,797\n"
+ "Bem recebido, de Houston.\n"
+ "Apollo Três aqui.\n\n"
+ "5\n"
+ "00:01:44,340 --> 00:01:48,385\n"
+ "Apollo Três, está tudo bem aqui.\n\n"
+ "6\n"
+ "00:01:49,428 --> 00:01:52,973\n"
+ "- Lee, você pode me copiar?\n"
+ "- Você é recebido, Capcom. Que falador.";
final String subst = "$1\\n<font color=#FFFF00>";
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