improve solution for regular expression matching.