refactore and add word scanner to handle regex logic