first version of optimizer, pattern by string in end or beginning