Added regex patterns and re-factored the implementation