Refactor code to use class re.Scanner