smart trailing pattern length matching.