Refactoring for regular expression