Add multi-pattern support.
Fix trailing character bug.