regex generator using trie