checking a string pattern by comparing characters