用Java 正则表达式对《Yes Prime Minister》字幕台词进行文本处理,附上《Yes Prime Minister》字幕台词文件
http://www.yyets.com/php/subtitle/31636
Yes Prime Minister S06E01 (15th January 2013)[PDTV(XviD)].简体&英文.ass
针对欧洲金融危机所进行的磋商\N{\fn微软雅黑}{\b0}{\fs14}{\3c&H202020&}{\shad1}There's been no breakthrough in the month-long negotiations
->
针对欧洲金融危机所进行的磋商\N
There's been no breakthrough in the month-long negotiations
Dialogue: 0,0:00:32.38,0:00:35.11,*Default,NTP,0000,0000,0000,,{\fn微软雅黑}{\b0}{\fs14}{\3c&H202020&}{\shad1}There's been no breakthrough in the month-long negotiations
->
There's been no breakthrough in the month-long negotiations
Dialogue: 0,0:00:32.38,0:00:35.11,*Default,NTP,0000,0000,0000,,针对欧洲金融危机所进行的磋商
->
针对欧洲金融危机所进行的磋商
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class testRex {
/**
* @param args
*/
public static void main(String[] args) {
// 这一问题达成协议\N{\fn微软雅黑}{\b0}{\fs14}{\3c&H202020&}{\shad1}has so far
// eluded all three governments,
String oriText = "这一问题达成协议\\N{\\fn微软雅黑}{\\b0}{\\fs14}{\\3c&H202020&}{\\shad1}has so far eluded all three governments,";
System.out.println(oriText);
String newText = oriText.replaceAll("\\{(.*)\\}", "##");
// String newText = oriText.replaceAll("\\{([^}]*)\\}", "##");
System.out.println(newText);
String charsetName = "GBK";
String inFilePathName = "D:\\temp\\temp1\\1.txt";
File file = new File(inFilePathName);
String outFilePathName = "D:\\temp\\temp1\\Yes Prime Minister S06E01 (15th January 2013)[PDTV(XviD)].简体.txt";
try {
InputStreamReader insReader = new InputStreamReader(
new FileInputStream(file), charsetName);
BufferedReader in = new BufferedReader(insReader);// 要读取的文本文件
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(outFilePathName)), charsetName);
BufferedWriter br = new BufferedWriter(outputStreamWriter);// 输出的结果文件
String s = "";
Pattern pattern = Pattern.compile("\\{(.*)\\}");// 正则匹配sql结尾
Matcher m = null;
int i = 1;
while ((s = in.readLine()) != null) {
// if((s = in.readLine()) != null) {
// newText = s.replaceAll("\\{(.*)\\}", "##");
// System.out.println(newText);
// System.out.println(s);
// m = pattern.matcher(s);
// if (m.find()) {
// System.out.println(i++);
// s = s.replaceAll("\\{(.*)\\}", "\r\n\t");// 替换
// }
// if (!s.matches(" *")) {// 剔除空白行
// br.write(s);
// br.write("\r\n");
// }
// s = s.replaceAll("^Dialogue(.*)\\}", "");
s = s.replaceAll("^Dialogue(.*)0000,,", "");
br.write(s);
br.write("\r\n");
}
// 关闭
in.close();
br.flush();
outputStreamWriter.close();
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
}
}
}