### Question:
RegexTrie { public String toRegex() { StringBuilder regex = new StringBuilder(); toRegex(root, regex); return regex.toString(); } RegexTrie();  RegexTrie(List<String> strings);  RegexTrie(String... strings); void addAll(List<String> strings); void add(String string); boolean contains(final String string); String toRegex();  }### Answer:
@Test public void testRegex() { String[] strings = new String[] {"", "A", "AB", "ABCDEF", "BC", "BB"}; String[] other = new String[] {"AA", "B", "BBB", "BCB", "ABC", "ABCD", "ABCDE", "ABCDEFF", "C"}; String regex = new RegexTrie(Arrays.asList(strings)).toRegex(); Pattern pattern = Pattern.compile(regex); for (String string : strings) { Assert.assertTrue(pattern.matcher(string).matches()); } for (String string : other) { Assert.assertFalse(pattern.matcher(string).matches()); } }