Java API for SRT subtitles

FearUs picture FearUs · Feb 21, 2011 · Viewed 13.6k times · Source

Is there any Java API for SRT subtitles ?

Answer

Panayotis picture Panayotis · Aug 2, 2011

The actual SRT parsing is performed through regular expressions, which Java is able to manipulate.

The actual regexp is:

protected static final String nl = "\\\n";
protected static final String sp = "[ \\t]*";
Pattern.compile("(?s)(\\d+)" + sp + nl + "(\\d{1,2}):(\\d\\d):(\\d\\d),(\\d\\d\\d)" + sp + "-->"+ sp + "(\\d\\d):(\\d\\d):(\\d\\d),(\\d\\d\\d)" + sp + "(X1:\\d.*?)??" + nl + "(.*?)" + nl + nl);

group 2, 3, 4, and 5 is start time group 6, 7, 8, and 9 is finish time group 11 is subtitle text