fixed regex when containing whitespace, refactoring