Refactoring of the regular expression matching.
 More refactoring.