improve solution for regular expression.