Preprocessor { public static Set<String> find_simple_regex_abbreviations(File file) { if (!file.canRead()) { throw new IllegalArgumentException(file + " is non-existent or not readable"); } Set<String> potentials = new HashSet<String>(); String[] patterns = new String[] { "\\b([a-zA-Z]\\.)+", "((\\d)+\\.)+(\\d)+", }; String final_pattern = "("; for (String str : patterns) { final_pattern += str + "|"; } final_pattern = final_pattern.substring(0, final_pattern.length() - 1) + ")"; Pattern p = Pattern.compile(final_pattern); try { BufferedReader f = new BufferedReader(new FileReader(file)); String line; while ((line = f.readLine()) != null) { Matcher m = p.matcher(line); while (m.find()) { potentials.add(m.group(1)); } } } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(-1); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } return potentials; }  static void main(String[] args); static String preprocess(String file); static void removeuseless(String filename, String outfilename); static void usecomma(String filename, String outfilename,
			String charactersplit); static Set<String> find_abbreviations(File file); static Set<String> find_potential_abbreviations(File file); static Set<String> find_simple_regex_abbreviations(File file); static void removeBOM(String filename);  }
@Test public void testFind_simple_regex_abbreviations() throws IOException { File f = File.createTempFile("testFind_simple_regex_abbreviations" + new Random().nextLong(), "tmp"); BufferedWriter w = new BufferedWriter(new FileWriter(f)); String[][] abbreviations_results = new String[][] { { "U.S.A.'", "U.S.A." }, { "i.e.", "i.e." }, { "F.u.c.k.", "F.u.c.k." }, { "127.0.0.1", "127.0.0.1" }, { "-B42.42E42", "42.42" } }; for (String[] pair : abbreviations_results) { w.write(pair[0]); w.write("\n"); } w.write("\n"); w.write("Hello World. :)"); w.close(); Set<String> result = Preprocessor.find_simple_regex_abbreviations(f); Set<String> fails = new HashSet<String>(); for (String[] abbrv : abbreviations_results) { if (! result.remove(abbrv[1])){ fails.add(abbrv[1] + " not found from " + abbrv[0]); } } if (! result.isEmpty()){ for (String str : result) { fails.add(str + " found but not in regexpr"); } } if (!fails.isEmpty()){ for (String str : fails) { System.out.println("errors:\n======="); System.out.println(str); fail("Some patterns were either not found or some were found while not supposed to"); } } f.delete(); }