import java.io.*; public class RegexReplace2 { public static void main(String[] args) throws IOException { FileReader in = new FileReader(new File("old.txt")); String input = ""; int c; while ((c = in.read()) != -1) { input += (char) c; } in.close(); String inputArray[] = input.split("\""); String output = ""; String[] regexInArray = {"\\b(it|It) ", "\\b(\\w{8,20}),", "\\bI (\\w+) ", "\\bhimself\\b", "\\bThat\\b", "\\that\\b", "\\bThey\\b", "\\bthey\\b", "(\\w{7,20})\\.", "\\bhave to\\b", "\\bhave\\b", "\\b(his|her)\\b", "\\bhe\\b", "\\bHe\\b", "(\\w) (\\w{9,10})\\b", "( \\w{11,20})\\b", "\\?", "\\bare[^,]", "\\bis\\b", "\\bbe\\b", ",,"}; String[] regexOutArray = {"$0, like,", "$1, and stuff,", "I $1, like, ", "hisself", "That", "dat", "Dudes", "dudes", " $1 and whatnot.", "gotta", "got", "dude's", "dude", "Dude","$1, uh, $2", ", um,$1", ", you know?", "are totally", "is totally", "totally be", ","}; for (int j = 0; j < inputArray.length; j++) { if (j % 2 == 1) { for (int i = 0; i < regexInArray.length; i++) { inputArray[j] = inputArray[j].replaceAll(regexInArray[i], regexOutArray[i]); } output += "\"" + inputArray[j] + "\""; } else { input = inputArray[j]; output += inputArray[j]; } } System.out.println(output); FileWriter out = new FileWriter(new File("new.txt")); for (int i = 0; i < output.length(); i++) { out.write(output.charAt(i)); } out.close(); } }