rewrite leetcode regular expression matching