solve regular expression matching