SubString finds longest matching substring